fidl_next_protocol/
framework_error.rs1use core::fmt;
6use core::hint::unreachable_unchecked;
7use core::mem::MaybeUninit;
8
9use fidl_next_codec::{
10 munge, Decode, DecodeError, Encodable, Encode, EncodeError, EncodeRef, Slot, TakeFrom, WireI32,
11 ZeroPadding,
12};
13
14#[derive(Clone, Copy, Debug, PartialEq, Eq)]
16#[repr(i32)]
17pub enum FrameworkError {
18 UnknownMethod = -2,
20}
21
22#[derive(Clone, Copy)]
24#[repr(transparent)]
25pub struct WireFrameworkError {
26 inner: WireI32,
27}
28
29unsafe impl ZeroPadding for WireFrameworkError {
30 #[inline]
31 fn zero_padding(_: &mut MaybeUninit<Self>) {}
32}
33
34impl fmt::Debug for WireFrameworkError {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 FrameworkError::from(*self).fmt(f)
37 }
38}
39
40impl From<WireFrameworkError> for FrameworkError {
41 fn from(value: WireFrameworkError) -> Self {
42 match *value.inner {
43 -2 => Self::UnknownMethod,
44 _ => unsafe { unreachable_unchecked() },
45 }
46 }
47}
48
49unsafe impl<D: ?Sized> Decode<D> for WireFrameworkError {
50 fn decode(slot: Slot<'_, Self>, _: &mut D) -> Result<(), DecodeError> {
51 munge!(let Self { inner } = slot);
52 match **inner {
53 -2 => Ok(()),
54 code => Err(DecodeError::InvalidFrameworkError(code)),
55 }
56 }
57}
58
59impl Encodable for FrameworkError {
60 type Encoded = WireFrameworkError;
61}
62
63unsafe impl<E: ?Sized> Encode<E> for FrameworkError {
64 fn encode(
65 self,
66 encoder: &mut E,
67 out: &mut MaybeUninit<Self::Encoded>,
68 ) -> Result<(), EncodeError> {
69 self.encode_ref(encoder, out)
70 }
71}
72
73unsafe impl<E: ?Sized> EncodeRef<E> for FrameworkError {
74 fn encode_ref(
75 &self,
76 _: &mut E,
77 out: &mut MaybeUninit<Self::Encoded>,
78 ) -> Result<(), EncodeError> {
79 munge!(let WireFrameworkError { inner } = out);
80 inner.write(WireI32(match self {
81 Self::UnknownMethod => -2,
82 }));
83
84 Ok(())
85 }
86}
87
88impl TakeFrom<WireFrameworkError> for FrameworkError {
89 fn take_from(from: &WireFrameworkError) -> Self {
90 Self::from(*from)
91 }
92}