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