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, Slot, TakeFrom, WireI32,
11 ZeroPadding,
12};
13
14#[derive(Clone, Copy, Debug)]
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 &mut self,
66 _: &mut E,
67 out: &mut MaybeUninit<Self::Encoded>,
68 ) -> Result<(), EncodeError> {
69 munge!(let WireFrameworkError { inner } = out);
70 inner.write(WireI32(match self {
71 Self::UnknownMethod => -2,
72 }));
73
74 Ok(())
75 }
76}
77
78impl TakeFrom<WireFrameworkError> for FrameworkError {
79 fn take_from(from: &WireFrameworkError) -> Self {
80 Self::from(*from)
81 }
82}