fidl_next_codec/fuchsia/
rights.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 WireRights {
19 inner: WireU32,
20}
21
22unsafe impl Wire for WireRights {
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 WireRights {}
33
34impl WireRights {
35 pub fn to_rights(self) -> zx::Rights {
37 zx::Rights::from_bits_retain(*self.inner)
38 }
39}
40
41impl fmt::Debug for WireRights {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 self.to_rights().fmt(f)
44 }
45}
46
47unsafe impl<D: ?Sized> Decode<D> for WireRights {
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<WireRights, E> for zx::Rights {
59 fn encode(
60 self,
61 encoder: &mut E,
62 out: &mut MaybeUninit<WireRights>,
63 constraint: (),
64 ) -> Result<(), EncodeError> {
65 munge!(let WireRights { inner } = out);
66 self.bits().encode(encoder, inner, constraint)
67 }
68}
69
70unsafe impl<E: ?Sized> Encode<WireRights, E> for &zx::Rights {
71 fn encode(
72 self,
73 encoder: &mut E,
74 out: &mut MaybeUninit<WireRights>,
75 constraint: (),
76 ) -> Result<(), EncodeError> {
77 Encode::encode(*self, encoder, out, constraint)
78 }
79}
80
81impl FromWire<WireRights> for zx::Rights {
82 fn from_wire(wire: WireRights) -> Self {
83 Self::from_wire_ref(&wire)
84 }
85}
86
87impl FromWireRef<WireRights> for zx::Rights {
88 fn from_wire_ref(wire: &WireRights) -> Self {
89 Self::from_bits_retain(*wire.inner)
90 }
91}
92
93impl IntoNatural for WireRights {
94 type Natural = zx::Rights;
95}