fidl_next_codec/fuchsia/
object_type.rs1use core::fmt;
6use core::mem::MaybeUninit;
7
8use munge::munge;
9
10use crate::{
11 Constrained, Decode, DecodeError, Encode, EncodeError, FromWire, FromWireRef, IntoNatural,
12 Slot, Unconstrained, Wire, WireU32,
13};
14
15#[derive(Clone, Copy)]
17#[repr(transparent)]
18pub struct WireObjectType {
19 inner: WireU32,
20}
21
22unsafe impl Wire for WireObjectType {
23 type Owned<'de> = Self;
24
25 #[inline]
26 fn zero_padding(out: &mut MaybeUninit<Self>) {
27 munge!(let Self { inner } = out);
28 WireU32::zero_padding(inner);
29 }
30}
31
32impl Unconstrained for WireObjectType {}
33
34impl WireObjectType {
35 pub fn to_object_type(self) -> zx::ObjectType {
37 zx::ObjectType::from_raw(*self.inner)
38 }
39}
40
41impl fmt::Debug for WireObjectType {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 self.to_object_type().fmt(f)
44 }
45}
46
47unsafe impl<D: ?Sized> Decode<D> for WireObjectType {
48 fn decode(
49 slot: Slot<'_, Self>,
50 decoder: &mut D,
51 _: <Self as Constrained>::Constraint,
52 ) -> Result<(), DecodeError> {
53 munge!(let Self { inner } = slot);
54 WireU32::decode(inner, decoder, ())
55 }
56}
57
58unsafe impl<E: ?Sized> Encode<WireObjectType, E> for zx::ObjectType {
59 fn encode(
60 self,
61 encoder: &mut E,
62 out: &mut MaybeUninit<WireObjectType>,
63 constraint: (),
64 ) -> Result<(), EncodeError> {
65 munge!(let WireObjectType { inner } = out);
66 self.into_raw().encode(encoder, inner, constraint)
67 }
68}
69
70unsafe impl<E: ?Sized> Encode<WireObjectType, E> for &zx::ObjectType {
71 fn encode(
72 self,
73 encoder: &mut E,
74 out: &mut MaybeUninit<WireObjectType>,
75 constraint: (),
76 ) -> Result<(), EncodeError> {
77 Encode::encode(*self, encoder, out, constraint)
78 }
79}
80
81impl FromWire<WireObjectType> for zx::ObjectType {
82 fn from_wire(wire: WireObjectType) -> Self {
83 Self::from_wire_ref(&wire)
84 }
85}
86
87impl FromWireRef<WireObjectType> for zx::ObjectType {
88 fn from_wire_ref(wire: &WireObjectType) -> Self {
89 Self::from_raw(*wire.inner)
90 }
91}
92
93impl IntoNatural for WireObjectType {
94 type Natural = zx::ObjectType;
95}