fidl_next_protocol/wire/
epitaph.rs1use core::mem::MaybeUninit;
6
7use fidl_next_codec::{
8 Constrained, Decode, DecodeError, Encode, EncodeError, Slot, ValidationError, Wire,
9};
10use zerocopy::IntoBytes;
11
12use crate::wire;
13
14#[derive(Clone, Copy, Debug, IntoBytes)]
16#[repr(C)]
17pub struct Epitaph {
18 pub error: wire::Int32,
20}
21
22impl Epitaph {
23 pub fn new(error: i32) -> Self {
25 Self { error: wire::Int32(error) }
26 }
27}
28
29impl Constrained for Epitaph {
30 type Constraint = ();
31
32 fn validate(_: Slot<'_, Self>, _: Self::Constraint) -> Result<(), ValidationError> {
33 Ok(())
34 }
35}
36
37unsafe impl Wire for Epitaph {
38 type Narrowed<'de> = Self;
39
40 #[inline]
41 fn zero_padding(_: &mut MaybeUninit<Self>) {
42 }
44}
45
46unsafe impl<E: ?Sized> Encode<Epitaph, E> for Epitaph {
47 #[inline]
48 fn encode(self, _: &mut E, out: &mut MaybeUninit<Epitaph>, _: ()) -> Result<(), EncodeError> {
49 out.write(self);
50 Ok(())
51 }
52}
53
54unsafe impl<E: ?Sized> Encode<Epitaph, E> for &Epitaph {
55 #[inline]
56 fn encode(
57 self,
58 encoder: &mut E,
59 out: &mut MaybeUninit<Epitaph>,
60 constraint: (),
61 ) -> Result<(), EncodeError> {
62 Encode::encode(*self, encoder, out, constraint)
63 }
64}
65
66unsafe impl<D: ?Sized> Decode<D> for Epitaph {
67 #[inline]
68 fn decode(_: Slot<'_, Self>, _: &mut D, _: ()) -> Result<(), DecodeError> {
69 Ok(())
70 }
71}