fidl_examples_calculator_common/
fidl_examples_calculator_common.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
12#[repr(u32)]
13pub enum DivisionError {
14    DivideByZero = 1,
15}
16
17impl DivisionError {
18    #[inline]
19    pub fn from_primitive(prim: u32) -> Option<Self> {
20        match prim {
21            1 => Some(Self::DivideByZero),
22            _ => None,
23        }
24    }
25
26    #[inline]
27    pub const fn into_primitive(self) -> u32 {
28        self as u32
29    }
30
31    #[deprecated = "Strict enums should not use `is_unknown`"]
32    #[inline]
33    pub fn is_unknown(&self) -> bool {
34        false
35    }
36}
37
38#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
39#[repr(C)]
40pub struct CalculatorAddRequest {
41    pub a: i32,
42    pub b: i32,
43}
44
45impl fidl::Persistable for CalculatorAddRequest {}
46
47#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
48#[repr(C)]
49pub struct CalculatorDivideRequest {
50    pub dividend: i32,
51    pub divisor: i32,
52}
53
54impl fidl::Persistable for CalculatorDivideRequest {}
55
56#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
57#[repr(C)]
58pub struct CalculatorOnErrorRequest {
59    pub status_code: u32,
60}
61
62impl fidl::Persistable for CalculatorOnErrorRequest {}
63
64#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
65#[repr(C)]
66pub struct CalculatorAddResponse {
67    pub sum: i32,
68}
69
70impl fidl::Persistable for CalculatorAddResponse {}
71
72#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
73#[repr(C)]
74pub struct CalculatorDivideResponse {
75    pub quotient: i32,
76    pub remainder: i32,
77}
78
79impl fidl::Persistable for CalculatorDivideResponse {}
80
81mod internal {
82    use super::*;
83    unsafe impl fidl::encoding::TypeMarker for DivisionError {
84        type Owned = Self;
85
86        #[inline(always)]
87        fn inline_align(_context: fidl::encoding::Context) -> usize {
88            std::mem::align_of::<u32>()
89        }
90
91        #[inline(always)]
92        fn inline_size(_context: fidl::encoding::Context) -> usize {
93            std::mem::size_of::<u32>()
94        }
95
96        #[inline(always)]
97        fn encode_is_copy() -> bool {
98            true
99        }
100
101        #[inline(always)]
102        fn decode_is_copy() -> bool {
103            false
104        }
105    }
106
107    impl fidl::encoding::ValueTypeMarker for DivisionError {
108        type Borrowed<'a> = Self;
109        #[inline(always)]
110        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
111            *value
112        }
113    }
114
115    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for DivisionError {
116        #[inline]
117        unsafe fn encode(
118            self,
119            encoder: &mut fidl::encoding::Encoder<'_, D>,
120            offset: usize,
121            _depth: fidl::encoding::Depth,
122        ) -> fidl::Result<()> {
123            encoder.debug_check_bounds::<Self>(offset);
124            encoder.write_num(self.into_primitive(), offset);
125            Ok(())
126        }
127    }
128
129    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DivisionError {
130        #[inline(always)]
131        fn new_empty() -> Self {
132            Self::DivideByZero
133        }
134
135        #[inline]
136        unsafe fn decode(
137            &mut self,
138            decoder: &mut fidl::encoding::Decoder<'_, D>,
139            offset: usize,
140            _depth: fidl::encoding::Depth,
141        ) -> fidl::Result<()> {
142            decoder.debug_check_bounds::<Self>(offset);
143            let prim = decoder.read_num::<u32>(offset);
144
145            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
146            Ok(())
147        }
148    }
149
150    impl fidl::encoding::ValueTypeMarker for CalculatorAddRequest {
151        type Borrowed<'a> = &'a Self;
152        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
153            value
154        }
155    }
156
157    unsafe impl fidl::encoding::TypeMarker for CalculatorAddRequest {
158        type Owned = Self;
159
160        #[inline(always)]
161        fn inline_align(_context: fidl::encoding::Context) -> usize {
162            4
163        }
164
165        #[inline(always)]
166        fn inline_size(_context: fidl::encoding::Context) -> usize {
167            8
168        }
169        #[inline(always)]
170        fn encode_is_copy() -> bool {
171            true
172        }
173
174        #[inline(always)]
175        fn decode_is_copy() -> bool {
176            true
177        }
178    }
179
180    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<CalculatorAddRequest, D>
181        for &CalculatorAddRequest
182    {
183        #[inline]
184        unsafe fn encode(
185            self,
186            encoder: &mut fidl::encoding::Encoder<'_, D>,
187            offset: usize,
188            _depth: fidl::encoding::Depth,
189        ) -> fidl::Result<()> {
190            encoder.debug_check_bounds::<CalculatorAddRequest>(offset);
191            unsafe {
192                // Copy the object into the buffer.
193                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
194                (buf_ptr as *mut CalculatorAddRequest)
195                    .write_unaligned((self as *const CalculatorAddRequest).read());
196                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
197                // done second because the memcpy will write garbage to these bytes.
198            }
199            Ok(())
200        }
201    }
202    unsafe impl<
203            D: fidl::encoding::ResourceDialect,
204            T0: fidl::encoding::Encode<i32, D>,
205            T1: fidl::encoding::Encode<i32, D>,
206        > fidl::encoding::Encode<CalculatorAddRequest, D> for (T0, T1)
207    {
208        #[inline]
209        unsafe fn encode(
210            self,
211            encoder: &mut fidl::encoding::Encoder<'_, D>,
212            offset: usize,
213            depth: fidl::encoding::Depth,
214        ) -> fidl::Result<()> {
215            encoder.debug_check_bounds::<CalculatorAddRequest>(offset);
216            // Zero out padding regions. There's no need to apply masks
217            // because the unmasked parts will be overwritten by fields.
218            // Write the fields.
219            self.0.encode(encoder, offset + 0, depth)?;
220            self.1.encode(encoder, offset + 4, depth)?;
221            Ok(())
222        }
223    }
224
225    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for CalculatorAddRequest {
226        #[inline(always)]
227        fn new_empty() -> Self {
228            Self { a: fidl::new_empty!(i32, D), b: fidl::new_empty!(i32, D) }
229        }
230
231        #[inline]
232        unsafe fn decode(
233            &mut self,
234            decoder: &mut fidl::encoding::Decoder<'_, D>,
235            offset: usize,
236            _depth: fidl::encoding::Depth,
237        ) -> fidl::Result<()> {
238            decoder.debug_check_bounds::<Self>(offset);
239            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
240            // Verify that padding bytes are zero.
241            // Copy from the buffer into the object.
242            unsafe {
243                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
244            }
245            Ok(())
246        }
247    }
248
249    impl fidl::encoding::ValueTypeMarker for CalculatorDivideRequest {
250        type Borrowed<'a> = &'a Self;
251        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
252            value
253        }
254    }
255
256    unsafe impl fidl::encoding::TypeMarker for CalculatorDivideRequest {
257        type Owned = Self;
258
259        #[inline(always)]
260        fn inline_align(_context: fidl::encoding::Context) -> usize {
261            4
262        }
263
264        #[inline(always)]
265        fn inline_size(_context: fidl::encoding::Context) -> usize {
266            8
267        }
268        #[inline(always)]
269        fn encode_is_copy() -> bool {
270            true
271        }
272
273        #[inline(always)]
274        fn decode_is_copy() -> bool {
275            true
276        }
277    }
278
279    unsafe impl<D: fidl::encoding::ResourceDialect>
280        fidl::encoding::Encode<CalculatorDivideRequest, D> for &CalculatorDivideRequest
281    {
282        #[inline]
283        unsafe fn encode(
284            self,
285            encoder: &mut fidl::encoding::Encoder<'_, D>,
286            offset: usize,
287            _depth: fidl::encoding::Depth,
288        ) -> fidl::Result<()> {
289            encoder.debug_check_bounds::<CalculatorDivideRequest>(offset);
290            unsafe {
291                // Copy the object into the buffer.
292                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
293                (buf_ptr as *mut CalculatorDivideRequest)
294                    .write_unaligned((self as *const CalculatorDivideRequest).read());
295                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
296                // done second because the memcpy will write garbage to these bytes.
297            }
298            Ok(())
299        }
300    }
301    unsafe impl<
302            D: fidl::encoding::ResourceDialect,
303            T0: fidl::encoding::Encode<i32, D>,
304            T1: fidl::encoding::Encode<i32, D>,
305        > fidl::encoding::Encode<CalculatorDivideRequest, D> for (T0, T1)
306    {
307        #[inline]
308        unsafe fn encode(
309            self,
310            encoder: &mut fidl::encoding::Encoder<'_, D>,
311            offset: usize,
312            depth: fidl::encoding::Depth,
313        ) -> fidl::Result<()> {
314            encoder.debug_check_bounds::<CalculatorDivideRequest>(offset);
315            // Zero out padding regions. There's no need to apply masks
316            // because the unmasked parts will be overwritten by fields.
317            // Write the fields.
318            self.0.encode(encoder, offset + 0, depth)?;
319            self.1.encode(encoder, offset + 4, depth)?;
320            Ok(())
321        }
322    }
323
324    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
325        for CalculatorDivideRequest
326    {
327        #[inline(always)]
328        fn new_empty() -> Self {
329            Self { dividend: fidl::new_empty!(i32, D), divisor: fidl::new_empty!(i32, D) }
330        }
331
332        #[inline]
333        unsafe fn decode(
334            &mut self,
335            decoder: &mut fidl::encoding::Decoder<'_, D>,
336            offset: usize,
337            _depth: fidl::encoding::Depth,
338        ) -> fidl::Result<()> {
339            decoder.debug_check_bounds::<Self>(offset);
340            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
341            // Verify that padding bytes are zero.
342            // Copy from the buffer into the object.
343            unsafe {
344                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
345            }
346            Ok(())
347        }
348    }
349
350    impl fidl::encoding::ValueTypeMarker for CalculatorOnErrorRequest {
351        type Borrowed<'a> = &'a Self;
352        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
353            value
354        }
355    }
356
357    unsafe impl fidl::encoding::TypeMarker for CalculatorOnErrorRequest {
358        type Owned = Self;
359
360        #[inline(always)]
361        fn inline_align(_context: fidl::encoding::Context) -> usize {
362            4
363        }
364
365        #[inline(always)]
366        fn inline_size(_context: fidl::encoding::Context) -> usize {
367            4
368        }
369        #[inline(always)]
370        fn encode_is_copy() -> bool {
371            true
372        }
373
374        #[inline(always)]
375        fn decode_is_copy() -> bool {
376            true
377        }
378    }
379
380    unsafe impl<D: fidl::encoding::ResourceDialect>
381        fidl::encoding::Encode<CalculatorOnErrorRequest, D> for &CalculatorOnErrorRequest
382    {
383        #[inline]
384        unsafe fn encode(
385            self,
386            encoder: &mut fidl::encoding::Encoder<'_, D>,
387            offset: usize,
388            _depth: fidl::encoding::Depth,
389        ) -> fidl::Result<()> {
390            encoder.debug_check_bounds::<CalculatorOnErrorRequest>(offset);
391            unsafe {
392                // Copy the object into the buffer.
393                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
394                (buf_ptr as *mut CalculatorOnErrorRequest)
395                    .write_unaligned((self as *const CalculatorOnErrorRequest).read());
396                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
397                // done second because the memcpy will write garbage to these bytes.
398            }
399            Ok(())
400        }
401    }
402    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u32, D>>
403        fidl::encoding::Encode<CalculatorOnErrorRequest, D> for (T0,)
404    {
405        #[inline]
406        unsafe fn encode(
407            self,
408            encoder: &mut fidl::encoding::Encoder<'_, D>,
409            offset: usize,
410            depth: fidl::encoding::Depth,
411        ) -> fidl::Result<()> {
412            encoder.debug_check_bounds::<CalculatorOnErrorRequest>(offset);
413            // Zero out padding regions. There's no need to apply masks
414            // because the unmasked parts will be overwritten by fields.
415            // Write the fields.
416            self.0.encode(encoder, offset + 0, depth)?;
417            Ok(())
418        }
419    }
420
421    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
422        for CalculatorOnErrorRequest
423    {
424        #[inline(always)]
425        fn new_empty() -> Self {
426            Self { status_code: fidl::new_empty!(u32, D) }
427        }
428
429        #[inline]
430        unsafe fn decode(
431            &mut self,
432            decoder: &mut fidl::encoding::Decoder<'_, D>,
433            offset: usize,
434            _depth: fidl::encoding::Depth,
435        ) -> fidl::Result<()> {
436            decoder.debug_check_bounds::<Self>(offset);
437            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
438            // Verify that padding bytes are zero.
439            // Copy from the buffer into the object.
440            unsafe {
441                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 4);
442            }
443            Ok(())
444        }
445    }
446
447    impl fidl::encoding::ValueTypeMarker for CalculatorAddResponse {
448        type Borrowed<'a> = &'a Self;
449        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
450            value
451        }
452    }
453
454    unsafe impl fidl::encoding::TypeMarker for CalculatorAddResponse {
455        type Owned = Self;
456
457        #[inline(always)]
458        fn inline_align(_context: fidl::encoding::Context) -> usize {
459            4
460        }
461
462        #[inline(always)]
463        fn inline_size(_context: fidl::encoding::Context) -> usize {
464            4
465        }
466        #[inline(always)]
467        fn encode_is_copy() -> bool {
468            true
469        }
470
471        #[inline(always)]
472        fn decode_is_copy() -> bool {
473            true
474        }
475    }
476
477    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<CalculatorAddResponse, D>
478        for &CalculatorAddResponse
479    {
480        #[inline]
481        unsafe fn encode(
482            self,
483            encoder: &mut fidl::encoding::Encoder<'_, D>,
484            offset: usize,
485            _depth: fidl::encoding::Depth,
486        ) -> fidl::Result<()> {
487            encoder.debug_check_bounds::<CalculatorAddResponse>(offset);
488            unsafe {
489                // Copy the object into the buffer.
490                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
491                (buf_ptr as *mut CalculatorAddResponse)
492                    .write_unaligned((self as *const CalculatorAddResponse).read());
493                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
494                // done second because the memcpy will write garbage to these bytes.
495            }
496            Ok(())
497        }
498    }
499    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<i32, D>>
500        fidl::encoding::Encode<CalculatorAddResponse, D> for (T0,)
501    {
502        #[inline]
503        unsafe fn encode(
504            self,
505            encoder: &mut fidl::encoding::Encoder<'_, D>,
506            offset: usize,
507            depth: fidl::encoding::Depth,
508        ) -> fidl::Result<()> {
509            encoder.debug_check_bounds::<CalculatorAddResponse>(offset);
510            // Zero out padding regions. There's no need to apply masks
511            // because the unmasked parts will be overwritten by fields.
512            // Write the fields.
513            self.0.encode(encoder, offset + 0, depth)?;
514            Ok(())
515        }
516    }
517
518    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for CalculatorAddResponse {
519        #[inline(always)]
520        fn new_empty() -> Self {
521            Self { sum: fidl::new_empty!(i32, D) }
522        }
523
524        #[inline]
525        unsafe fn decode(
526            &mut self,
527            decoder: &mut fidl::encoding::Decoder<'_, D>,
528            offset: usize,
529            _depth: fidl::encoding::Depth,
530        ) -> fidl::Result<()> {
531            decoder.debug_check_bounds::<Self>(offset);
532            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
533            // Verify that padding bytes are zero.
534            // Copy from the buffer into the object.
535            unsafe {
536                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 4);
537            }
538            Ok(())
539        }
540    }
541
542    impl fidl::encoding::ValueTypeMarker for CalculatorDivideResponse {
543        type Borrowed<'a> = &'a Self;
544        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
545            value
546        }
547    }
548
549    unsafe impl fidl::encoding::TypeMarker for CalculatorDivideResponse {
550        type Owned = Self;
551
552        #[inline(always)]
553        fn inline_align(_context: fidl::encoding::Context) -> usize {
554            4
555        }
556
557        #[inline(always)]
558        fn inline_size(_context: fidl::encoding::Context) -> usize {
559            8
560        }
561        #[inline(always)]
562        fn encode_is_copy() -> bool {
563            true
564        }
565
566        #[inline(always)]
567        fn decode_is_copy() -> bool {
568            true
569        }
570    }
571
572    unsafe impl<D: fidl::encoding::ResourceDialect>
573        fidl::encoding::Encode<CalculatorDivideResponse, D> for &CalculatorDivideResponse
574    {
575        #[inline]
576        unsafe fn encode(
577            self,
578            encoder: &mut fidl::encoding::Encoder<'_, D>,
579            offset: usize,
580            _depth: fidl::encoding::Depth,
581        ) -> fidl::Result<()> {
582            encoder.debug_check_bounds::<CalculatorDivideResponse>(offset);
583            unsafe {
584                // Copy the object into the buffer.
585                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
586                (buf_ptr as *mut CalculatorDivideResponse)
587                    .write_unaligned((self as *const CalculatorDivideResponse).read());
588                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
589                // done second because the memcpy will write garbage to these bytes.
590            }
591            Ok(())
592        }
593    }
594    unsafe impl<
595            D: fidl::encoding::ResourceDialect,
596            T0: fidl::encoding::Encode<i32, D>,
597            T1: fidl::encoding::Encode<i32, D>,
598        > fidl::encoding::Encode<CalculatorDivideResponse, D> for (T0, T1)
599    {
600        #[inline]
601        unsafe fn encode(
602            self,
603            encoder: &mut fidl::encoding::Encoder<'_, D>,
604            offset: usize,
605            depth: fidl::encoding::Depth,
606        ) -> fidl::Result<()> {
607            encoder.debug_check_bounds::<CalculatorDivideResponse>(offset);
608            // Zero out padding regions. There's no need to apply masks
609            // because the unmasked parts will be overwritten by fields.
610            // Write the fields.
611            self.0.encode(encoder, offset + 0, depth)?;
612            self.1.encode(encoder, offset + 4, depth)?;
613            Ok(())
614        }
615    }
616
617    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
618        for CalculatorDivideResponse
619    {
620        #[inline(always)]
621        fn new_empty() -> Self {
622            Self { quotient: fidl::new_empty!(i32, D), remainder: fidl::new_empty!(i32, D) }
623        }
624
625        #[inline]
626        unsafe fn decode(
627            &mut self,
628            decoder: &mut fidl::encoding::Decoder<'_, D>,
629            offset: usize,
630            _depth: fidl::encoding::Depth,
631        ) -> fidl::Result<()> {
632            decoder.debug_check_bounds::<Self>(offset);
633            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
634            // Verify that padding bytes are zero.
635            // Copy from the buffer into the object.
636            unsafe {
637                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
638            }
639            Ok(())
640        }
641    }
642}