fidl_next_fuchsia_mem/
fidl_next_fuchsia_mem.rs

1// DO NOT EDIT: This file is machine-generated by fidlgen
2#![warn(clippy::all)]
3#![allow(unused_parens, unused_variables, unused_mut, unused_imports, unreachable_code)]
4
5#[doc = " A buffer for data whose size is not necessarily a multiple of the page\n size.\n\n DEPRECATED: This type is superfluous and deprecated. Instead of using this type,\n use a zx.Handle:VMO object and store the size of the contents in the ZX_PROP_VMO_CONTENT_SIZE\n property.\n"]
6#[derive(Debug)]
7pub struct Buffer {
8    pub vmo: ::fidl_next::fuchsia::zx::Vmo,
9
10    pub size: u64,
11}
12
13impl ::fidl_next::Encodable for Buffer {
14    type Encoded = WireBuffer;
15}
16
17unsafe impl<___E> ::fidl_next::Encode<___E> for Buffer
18where
19    ___E: ::fidl_next::encoder::InternalHandleEncoder + ?Sized,
20    ___E: ::fidl_next::fuchsia::HandleEncoder,
21{
22    #[inline]
23    fn encode(
24        self,
25        encoder: &mut ___E,
26        out: &mut ::core::mem::MaybeUninit<Self::Encoded>,
27    ) -> Result<(), ::fidl_next::EncodeError> {
28        ::fidl_next::munge! {
29            let Self::Encoded {
30                vmo,
31                size,
32
33            } = out;
34        }
35
36        ::fidl_next::Encode::encode(self.vmo, encoder, vmo)?;
37
38        ::fidl_next::Encode::encode(self.size, encoder, size)?;
39
40        Ok(())
41    }
42}
43
44impl ::fidl_next::EncodableOption for Buffer {
45    type EncodedOption = ::fidl_next::WireBox<'static, WireBuffer>;
46}
47
48unsafe impl<___E> ::fidl_next::EncodeOption<___E> for Buffer
49where
50    ___E: ::fidl_next::Encoder + ?Sized,
51    Buffer: ::fidl_next::Encode<___E>,
52{
53    #[inline]
54    fn encode_option(
55        this: Option<Self>,
56        encoder: &mut ___E,
57        out: &mut ::core::mem::MaybeUninit<Self::EncodedOption>,
58    ) -> Result<(), ::fidl_next::EncodeError> {
59        if let Some(inner) = this {
60            ::fidl_next::EncoderExt::encode_next(encoder, inner)?;
61            ::fidl_next::WireBox::encode_present(out);
62        } else {
63            ::fidl_next::WireBox::encode_absent(out);
64        }
65
66        Ok(())
67    }
68}
69
70impl ::fidl_next::FromWire<WireBuffer> for Buffer {
71    #[inline]
72    fn from_wire(wire: WireBuffer) -> Self {
73        Self {
74            vmo: ::fidl_next::FromWire::from_wire(wire.vmo),
75
76            size: ::fidl_next::FromWire::from_wire(wire.size),
77        }
78    }
79}
80
81/// The wire type corresponding to [`Buffer`].
82#[derive(Debug)]
83#[repr(C)]
84pub struct WireBuffer {
85    pub vmo: ::fidl_next::fuchsia::WireVmo,
86
87    pub size: ::fidl_next::WireU64,
88}
89
90unsafe impl ::fidl_next::Wire for WireBuffer {
91    type Decoded<'de> = WireBuffer;
92
93    #[inline]
94    fn zero_padding(out: &mut ::core::mem::MaybeUninit<Self>) {
95        unsafe {
96            out.as_mut_ptr().cast::<u8>().add(4).write_bytes(0, 4);
97        }
98    }
99}
100
101unsafe impl<___D> ::fidl_next::Decode<___D> for WireBuffer
102where
103    ___D: ::fidl_next::decoder::InternalHandleDecoder + ?Sized,
104    ___D: ::fidl_next::fuchsia::HandleDecoder,
105{
106    fn decode(
107        slot: ::fidl_next::Slot<'_, Self>,
108        decoder: &mut ___D,
109    ) -> Result<(), ::fidl_next::DecodeError> {
110        ::fidl_next::munge! {
111            let Self {
112                mut vmo,
113                mut size,
114
115            } = slot;
116        }
117
118        ::fidl_next::Decode::decode(vmo.as_mut(), decoder)?;
119
120        ::fidl_next::Decode::decode(size.as_mut(), decoder)?;
121
122        Ok(())
123    }
124}
125
126#[doc = " Binary data that might be stored inline or in a VMO.\n\n Useful for performance-sensitive protocols that sometimes receive small\n amounts of binary data (i.e., which is more efficient to provide using\n `bytes`) but also need to support arbitrary amounts of data (i.e., which\n need to be provided out-of-line in a `Buffer`).\n"]
127#[derive(Debug)]
128pub enum Data {
129    Bytes(Vec<u8>),
130
131    Buffer(crate::Buffer),
132
133    UnknownOrdinal_(u64),
134}
135
136impl ::fidl_next::Encodable for Data {
137    type Encoded = WireData<'static>;
138}
139
140unsafe impl<___E> ::fidl_next::Encode<___E> for Data
141where
142    ___E: ::fidl_next::encoder::InternalHandleEncoder + ?Sized,
143    ___E: ::fidl_next::Encoder,
144    ___E: ::fidl_next::fuchsia::HandleEncoder,
145{
146    #[inline]
147    fn encode(
148        self,
149        encoder: &mut ___E,
150        out: &mut ::core::mem::MaybeUninit<Self::Encoded>,
151    ) -> Result<(), ::fidl_next::EncodeError> {
152        ::fidl_next::munge!(let WireData { raw, _phantom: _ } = out);
153
154        match self {
155            Self::Bytes(value) => {
156                ::fidl_next::RawWireUnion::encode_as::<___E, Vec<u8>>(value, 1, encoder, raw)?
157            }
158
159            Self::Buffer(value) => {
160                ::fidl_next::RawWireUnion::encode_as::<___E, crate::Buffer>(value, 2, encoder, raw)?
161            }
162
163            Self::UnknownOrdinal_(ordinal) => {
164                return Err(::fidl_next::EncodeError::UnknownUnionOrdinal(ordinal as usize));
165            }
166        }
167
168        Ok(())
169    }
170}
171
172impl ::fidl_next::EncodableOption for Data {
173    type EncodedOption = WireOptionalData<'static>;
174}
175
176unsafe impl<___E> ::fidl_next::EncodeOption<___E> for Data
177where
178    ___E: ?Sized,
179    Data: ::fidl_next::Encode<___E>,
180{
181    #[inline]
182    fn encode_option(
183        this: Option<Self>,
184        encoder: &mut ___E,
185        out: &mut ::core::mem::MaybeUninit<Self::EncodedOption>,
186    ) -> Result<(), ::fidl_next::EncodeError> {
187        ::fidl_next::munge!(let WireOptionalData { raw, _phantom: _ } = &mut *out);
188
189        if let Some(inner) = this {
190            let value_out = unsafe { &mut *out.as_mut_ptr().cast() };
191            ::fidl_next::Encode::encode(inner, encoder, value_out)?;
192        } else {
193            ::fidl_next::RawWireUnion::encode_absent(raw);
194        }
195
196        Ok(())
197    }
198}
199
200impl<'de> ::fidl_next::FromWire<WireData<'de>> for Data {
201    #[inline]
202    fn from_wire(wire: WireData<'de>) -> Self {
203        let wire = ::core::mem::ManuallyDrop::new(wire);
204        match wire.raw.ordinal() {
205            1 => Self::Bytes(::fidl_next::FromWire::from_wire(unsafe {
206                wire.raw.get().read_unchecked::<::fidl_next::WireVector<'de, u8>>()
207            })),
208
209            2 => Self::Buffer(::fidl_next::FromWire::from_wire(unsafe {
210                wire.raw.get().read_unchecked::<crate::WireBuffer>()
211            })),
212
213            _ => unsafe { ::core::hint::unreachable_unchecked() },
214        }
215    }
216}
217
218impl<'de> ::fidl_next::FromWireOption<WireOptionalData<'de>> for Box<Data> {
219    #[inline]
220    fn from_wire_option(wire: WireOptionalData<'de>) -> Option<Self> {
221        if let Some(inner) = wire.into_option() {
222            Some(Box::new(::fidl_next::FromWire::from_wire(inner)))
223        } else {
224            None
225        }
226    }
227}
228
229/// The wire type corresponding to [`Data`].
230#[repr(transparent)]
231pub struct WireData<'de> {
232    raw: ::fidl_next::RawWireUnion,
233    _phantom: ::core::marker::PhantomData<&'de mut [::fidl_next::Chunk]>,
234}
235
236impl<'de> Drop for WireData<'de> {
237    fn drop(&mut self) {
238        match self.raw.ordinal() {
239            1 => {
240                let _ =
241                    unsafe { self.raw.get().read_unchecked::<::fidl_next::WireVector<'de, u8>>() };
242            }
243
244            2 => {
245                let _ = unsafe { self.raw.get().read_unchecked::<crate::WireBuffer>() };
246            }
247
248            _ => (),
249        }
250    }
251}
252
253unsafe impl ::fidl_next::Wire for WireData<'static> {
254    type Decoded<'de> = WireData<'de>;
255
256    #[inline]
257    fn zero_padding(out: &mut ::core::mem::MaybeUninit<Self>) {
258        ::fidl_next::munge!(let Self { raw, _phantom: _ } = out);
259        ::fidl_next::RawWireUnion::zero_padding(raw);
260    }
261}
262
263pub mod data {
264    pub enum Ref<'de> {
265        Bytes(&'de ::fidl_next::WireVector<'de, u8>),
266
267        Buffer(&'de crate::WireBuffer),
268
269        UnknownOrdinal_(u64),
270    }
271}
272
273impl<'de> WireData<'de> {
274    pub fn as_ref(&self) -> crate::data::Ref<'_> {
275        match self.raw.ordinal() {
276            1 => crate::data::Ref::Bytes(unsafe {
277                self.raw.get().deref_unchecked::<::fidl_next::WireVector<'_, u8>>()
278            }),
279
280            2 => crate::data::Ref::Buffer(unsafe {
281                self.raw.get().deref_unchecked::<crate::WireBuffer>()
282            }),
283
284            unknown => crate::data::Ref::UnknownOrdinal_(unknown),
285        }
286    }
287}
288
289unsafe impl<___D> ::fidl_next::Decode<___D> for WireData<'static>
290where
291    ___D: ::fidl_next::decoder::InternalHandleDecoder + ?Sized,
292    ___D: ::fidl_next::Decoder,
293    ___D: ::fidl_next::fuchsia::HandleDecoder,
294{
295    fn decode(
296        mut slot: ::fidl_next::Slot<'_, Self>,
297        decoder: &mut ___D,
298    ) -> Result<(), ::fidl_next::DecodeError> {
299        ::fidl_next::munge!(let Self { mut raw, _phantom: _ } = slot.as_mut());
300        match ::fidl_next::RawWireUnion::encoded_ordinal(raw.as_mut()) {
301            1 => {
302                ::fidl_next::RawWireUnion::decode_as::<___D, ::fidl_next::WireVector<'static, u8>>(
303                    raw, decoder,
304                )?
305            }
306
307            2 => ::fidl_next::RawWireUnion::decode_as::<___D, crate::WireBuffer>(raw, decoder)?,
308
309            _ => ::fidl_next::RawWireUnion::decode_unknown(raw, decoder)?,
310        }
311
312        Ok(())
313    }
314}
315
316impl<'de> ::core::fmt::Debug for WireData<'de> {
317    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
318        match self.raw.ordinal() {
319            1 => unsafe {
320                self.raw.get().deref_unchecked::<::fidl_next::WireVector<'_, u8>>().fmt(f)
321            },
322            2 => unsafe { self.raw.get().deref_unchecked::<crate::WireBuffer>().fmt(f) },
323            _ => unsafe { ::core::hint::unreachable_unchecked() },
324        }
325    }
326}
327
328#[repr(transparent)]
329pub struct WireOptionalData<'de> {
330    raw: ::fidl_next::RawWireUnion,
331    _phantom: ::core::marker::PhantomData<&'de mut [::fidl_next::Chunk]>,
332}
333
334unsafe impl ::fidl_next::Wire for WireOptionalData<'static> {
335    type Decoded<'de> = WireOptionalData<'de>;
336
337    #[inline]
338    fn zero_padding(out: &mut ::core::mem::MaybeUninit<Self>) {
339        ::fidl_next::munge!(let Self { raw, _phantom: _ } = out);
340        ::fidl_next::RawWireUnion::zero_padding(raw);
341    }
342}
343
344impl<'de> WireOptionalData<'de> {
345    pub fn is_some(&self) -> bool {
346        self.raw.is_some()
347    }
348
349    pub fn is_none(&self) -> bool {
350        self.raw.is_none()
351    }
352
353    pub fn as_ref(&self) -> Option<&WireData<'de>> {
354        if self.is_some() { Some(unsafe { &*(self as *const Self).cast() }) } else { None }
355    }
356
357    pub fn into_option(self) -> Option<WireData<'de>> {
358        if self.is_some() {
359            Some(WireData { raw: self.raw, _phantom: ::core::marker::PhantomData })
360        } else {
361            None
362        }
363    }
364}
365
366unsafe impl<___D> ::fidl_next::Decode<___D> for WireOptionalData<'static>
367where
368    ___D: ::fidl_next::decoder::InternalHandleDecoder + ?Sized,
369    ___D: ::fidl_next::Decoder,
370    ___D: ::fidl_next::fuchsia::HandleDecoder,
371{
372    fn decode(
373        mut slot: ::fidl_next::Slot<'_, Self>,
374        decoder: &mut ___D,
375    ) -> Result<(), ::fidl_next::DecodeError> {
376        ::fidl_next::munge!(let Self { mut raw, _phantom: _ } = slot.as_mut());
377        match ::fidl_next::RawWireUnion::encoded_ordinal(raw.as_mut()) {
378            1 => {
379                ::fidl_next::RawWireUnion::decode_as::<___D, ::fidl_next::WireVector<'static, u8>>(
380                    raw, decoder,
381                )?
382            }
383
384            2 => ::fidl_next::RawWireUnion::decode_as::<___D, crate::WireBuffer>(raw, decoder)?,
385
386            0 => ::fidl_next::RawWireUnion::decode_absent(raw)?,
387            _ => ::fidl_next::RawWireUnion::decode_unknown(raw, decoder)?,
388        }
389
390        Ok(())
391    }
392}
393
394impl<'de> ::core::fmt::Debug for WireOptionalData<'de> {
395    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
396        self.as_ref().fmt(f)
397    }
398}
399
400#[doc = " A range of bytes within a VMO.\n"]
401#[derive(Debug)]
402pub struct Range {
403    pub vmo: ::fidl_next::fuchsia::zx::Vmo,
404
405    pub offset: u64,
406
407    pub size: u64,
408}
409
410impl ::fidl_next::Encodable for Range {
411    type Encoded = WireRange;
412}
413
414unsafe impl<___E> ::fidl_next::Encode<___E> for Range
415where
416    ___E: ::fidl_next::encoder::InternalHandleEncoder + ?Sized,
417    ___E: ::fidl_next::fuchsia::HandleEncoder,
418{
419    #[inline]
420    fn encode(
421        self,
422        encoder: &mut ___E,
423        out: &mut ::core::mem::MaybeUninit<Self::Encoded>,
424    ) -> Result<(), ::fidl_next::EncodeError> {
425        ::fidl_next::munge! {
426            let Self::Encoded {
427                vmo,
428                offset,
429                size,
430
431            } = out;
432        }
433
434        ::fidl_next::Encode::encode(self.vmo, encoder, vmo)?;
435
436        ::fidl_next::Encode::encode(self.offset, encoder, offset)?;
437
438        ::fidl_next::Encode::encode(self.size, encoder, size)?;
439
440        Ok(())
441    }
442}
443
444impl ::fidl_next::EncodableOption for Range {
445    type EncodedOption = ::fidl_next::WireBox<'static, WireRange>;
446}
447
448unsafe impl<___E> ::fidl_next::EncodeOption<___E> for Range
449where
450    ___E: ::fidl_next::Encoder + ?Sized,
451    Range: ::fidl_next::Encode<___E>,
452{
453    #[inline]
454    fn encode_option(
455        this: Option<Self>,
456        encoder: &mut ___E,
457        out: &mut ::core::mem::MaybeUninit<Self::EncodedOption>,
458    ) -> Result<(), ::fidl_next::EncodeError> {
459        if let Some(inner) = this {
460            ::fidl_next::EncoderExt::encode_next(encoder, inner)?;
461            ::fidl_next::WireBox::encode_present(out);
462        } else {
463            ::fidl_next::WireBox::encode_absent(out);
464        }
465
466        Ok(())
467    }
468}
469
470impl ::fidl_next::FromWire<WireRange> for Range {
471    #[inline]
472    fn from_wire(wire: WireRange) -> Self {
473        Self {
474            vmo: ::fidl_next::FromWire::from_wire(wire.vmo),
475
476            offset: ::fidl_next::FromWire::from_wire(wire.offset),
477
478            size: ::fidl_next::FromWire::from_wire(wire.size),
479        }
480    }
481}
482
483/// The wire type corresponding to [`Range`].
484#[derive(Debug)]
485#[repr(C)]
486pub struct WireRange {
487    pub vmo: ::fidl_next::fuchsia::WireVmo,
488
489    pub offset: ::fidl_next::WireU64,
490
491    pub size: ::fidl_next::WireU64,
492}
493
494unsafe impl ::fidl_next::Wire for WireRange {
495    type Decoded<'de> = WireRange;
496
497    #[inline]
498    fn zero_padding(out: &mut ::core::mem::MaybeUninit<Self>) {
499        unsafe {
500            out.as_mut_ptr().cast::<u8>().add(4).write_bytes(0, 4);
501        }
502    }
503}
504
505unsafe impl<___D> ::fidl_next::Decode<___D> for WireRange
506where
507    ___D: ::fidl_next::decoder::InternalHandleDecoder + ?Sized,
508    ___D: ::fidl_next::fuchsia::HandleDecoder,
509{
510    fn decode(
511        slot: ::fidl_next::Slot<'_, Self>,
512        decoder: &mut ___D,
513    ) -> Result<(), ::fidl_next::DecodeError> {
514        ::fidl_next::munge! {
515            let Self {
516                mut vmo,
517                mut offset,
518                mut size,
519
520            } = slot;
521        }
522
523        ::fidl_next::Decode::decode(vmo.as_mut(), decoder)?;
524
525        ::fidl_next::Decode::decode(offset.as_mut(), decoder)?;
526
527        ::fidl_next::Decode::decode(size.as_mut(), decoder)?;
528
529        Ok(())
530    }
531}
532
533/// Compatibility shims which mimic some API surfaces of the current Rust bindings.
534pub mod compat {
535
536    impl ::fidl_next::CompatFrom<crate::Buffer> for ::fidl_fuchsia_mem::Buffer {
537        #[inline]
538        fn compat_from(value: crate::Buffer) -> Self {
539            Self {
540                vmo: ::fidl_next::CompatFrom::compat_from(value.vmo),
541
542                size: ::fidl_next::CompatFrom::compat_from(value.size),
543            }
544        }
545    }
546
547    impl ::fidl_next::CompatFrom<::fidl_fuchsia_mem::Buffer> for crate::Buffer {
548        #[inline]
549        fn compat_from(value: ::fidl_fuchsia_mem::Buffer) -> Self {
550            Self {
551                vmo: ::fidl_next::CompatFrom::compat_from(value.vmo),
552
553                size: ::fidl_next::CompatFrom::compat_from(value.size),
554            }
555        }
556    }
557
558    impl ::fidl_next::CompatFrom<crate::Data> for ::fidl_fuchsia_mem::Data {
559        fn compat_from(value: crate::Data) -> Self {
560            match value {
561                crate::Data::Bytes(value) => {
562                    Self::Bytes(::fidl_next::CompatFrom::compat_from(value))
563                }
564
565                crate::Data::Buffer(value) => {
566                    Self::Buffer(::fidl_next::CompatFrom::compat_from(value))
567                }
568
569                crate::Data::UnknownOrdinal_(unknown_ordinal) => {
570                    Self::__SourceBreaking { unknown_ordinal }
571                }
572            }
573        }
574    }
575
576    impl ::fidl_next::CompatFrom<::fidl_fuchsia_mem::Data> for crate::Data {
577        fn compat_from(value: ::fidl_fuchsia_mem::Data) -> Self {
578            match value {
579                ::fidl_fuchsia_mem::Data::Bytes(value) => {
580                    Self::Bytes(::fidl_next::CompatFrom::compat_from(value))
581                }
582
583                ::fidl_fuchsia_mem::Data::Buffer(value) => {
584                    Self::Buffer(::fidl_next::CompatFrom::compat_from(value))
585                }
586
587                ::fidl_fuchsia_mem::Data::__SourceBreaking { unknown_ordinal } => {
588                    Self::UnknownOrdinal_(unknown_ordinal)
589                }
590            }
591        }
592    }
593
594    impl ::fidl_next::CompatFrom<crate::Range> for ::fidl_fuchsia_mem::Range {
595        #[inline]
596        fn compat_from(value: crate::Range) -> Self {
597            Self {
598                vmo: ::fidl_next::CompatFrom::compat_from(value.vmo),
599
600                offset: ::fidl_next::CompatFrom::compat_from(value.offset),
601
602                size: ::fidl_next::CompatFrom::compat_from(value.size),
603            }
604        }
605    }
606
607    impl ::fidl_next::CompatFrom<::fidl_fuchsia_mem::Range> for crate::Range {
608        #[inline]
609        fn compat_from(value: ::fidl_fuchsia_mem::Range) -> Self {
610            Self {
611                vmo: ::fidl_next::CompatFrom::compat_from(value.vmo),
612
613                offset: ::fidl_next::CompatFrom::compat_from(value.offset),
614
615                size: ::fidl_next::CompatFrom::compat_from(value.size),
616            }
617        }
618    }
619}