fidl_examples_canvas_addlinemetered_common/
fidl_examples_canvas_addlinemetered_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/// A line in 2D space.
12pub type Line = [Point; 2];
13
14/// A bounding box in 2D space. This is the result of "drawing" operations on our canvas, and what
15/// the server reports back to the client. These bounds are sufficient to contain all of the
16/// lines (inclusive) on a canvas at a given time.
17#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
18#[repr(C)]
19pub struct BoundingBox {
20    pub top_left: Point,
21    pub bottom_right: Point,
22}
23
24impl fidl::Persistable for BoundingBox {}
25
26#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
27#[repr(C)]
28pub struct InstanceAddLineRequest {
29    pub line: [Point; 2],
30}
31
32impl fidl::Persistable for InstanceAddLineRequest {}
33
34/// A point in 2D space.
35#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
36#[repr(C)]
37pub struct Point {
38    pub x: i64,
39    pub y: i64,
40}
41
42impl fidl::Persistable for Point {}
43
44mod internal {
45    use super::*;
46
47    impl fidl::encoding::ValueTypeMarker for BoundingBox {
48        type Borrowed<'a> = &'a Self;
49        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
50            value
51        }
52    }
53
54    unsafe impl fidl::encoding::TypeMarker for BoundingBox {
55        type Owned = Self;
56
57        #[inline(always)]
58        fn inline_align(_context: fidl::encoding::Context) -> usize {
59            8
60        }
61
62        #[inline(always)]
63        fn inline_size(_context: fidl::encoding::Context) -> usize {
64            32
65        }
66        #[inline(always)]
67        fn encode_is_copy() -> bool {
68            true
69        }
70
71        #[inline(always)]
72        fn decode_is_copy() -> bool {
73            true
74        }
75    }
76
77    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<BoundingBox, D>
78        for &BoundingBox
79    {
80        #[inline]
81        unsafe fn encode(
82            self,
83            encoder: &mut fidl::encoding::Encoder<'_, D>,
84            offset: usize,
85            _depth: fidl::encoding::Depth,
86        ) -> fidl::Result<()> {
87            encoder.debug_check_bounds::<BoundingBox>(offset);
88            unsafe {
89                // Copy the object into the buffer.
90                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
91                (buf_ptr as *mut BoundingBox).write_unaligned((self as *const BoundingBox).read());
92                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
93                // done second because the memcpy will write garbage to these bytes.
94            }
95            Ok(())
96        }
97    }
98    unsafe impl<
99            D: fidl::encoding::ResourceDialect,
100            T0: fidl::encoding::Encode<Point, D>,
101            T1: fidl::encoding::Encode<Point, D>,
102        > fidl::encoding::Encode<BoundingBox, D> for (T0, T1)
103    {
104        #[inline]
105        unsafe fn encode(
106            self,
107            encoder: &mut fidl::encoding::Encoder<'_, D>,
108            offset: usize,
109            depth: fidl::encoding::Depth,
110        ) -> fidl::Result<()> {
111            encoder.debug_check_bounds::<BoundingBox>(offset);
112            // Zero out padding regions. There's no need to apply masks
113            // because the unmasked parts will be overwritten by fields.
114            // Write the fields.
115            self.0.encode(encoder, offset + 0, depth)?;
116            self.1.encode(encoder, offset + 16, depth)?;
117            Ok(())
118        }
119    }
120
121    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BoundingBox {
122        #[inline(always)]
123        fn new_empty() -> Self {
124            Self { top_left: fidl::new_empty!(Point, D), bottom_right: fidl::new_empty!(Point, D) }
125        }
126
127        #[inline]
128        unsafe fn decode(
129            &mut self,
130            decoder: &mut fidl::encoding::Decoder<'_, D>,
131            offset: usize,
132            _depth: fidl::encoding::Depth,
133        ) -> fidl::Result<()> {
134            decoder.debug_check_bounds::<Self>(offset);
135            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
136            // Verify that padding bytes are zero.
137            // Copy from the buffer into the object.
138            unsafe {
139                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 32);
140            }
141            Ok(())
142        }
143    }
144
145    impl fidl::encoding::ValueTypeMarker for InstanceAddLineRequest {
146        type Borrowed<'a> = &'a Self;
147        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
148            value
149        }
150    }
151
152    unsafe impl fidl::encoding::TypeMarker for InstanceAddLineRequest {
153        type Owned = Self;
154
155        #[inline(always)]
156        fn inline_align(_context: fidl::encoding::Context) -> usize {
157            8
158        }
159
160        #[inline(always)]
161        fn inline_size(_context: fidl::encoding::Context) -> usize {
162            32
163        }
164        #[inline(always)]
165        fn encode_is_copy() -> bool {
166            true
167        }
168
169        #[inline(always)]
170        fn decode_is_copy() -> bool {
171            true
172        }
173    }
174
175    unsafe impl<D: fidl::encoding::ResourceDialect>
176        fidl::encoding::Encode<InstanceAddLineRequest, D> for &InstanceAddLineRequest
177    {
178        #[inline]
179        unsafe fn encode(
180            self,
181            encoder: &mut fidl::encoding::Encoder<'_, D>,
182            offset: usize,
183            _depth: fidl::encoding::Depth,
184        ) -> fidl::Result<()> {
185            encoder.debug_check_bounds::<InstanceAddLineRequest>(offset);
186            unsafe {
187                // Copy the object into the buffer.
188                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
189                (buf_ptr as *mut InstanceAddLineRequest)
190                    .write_unaligned((self as *const InstanceAddLineRequest).read());
191                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
192                // done second because the memcpy will write garbage to these bytes.
193            }
194            Ok(())
195        }
196    }
197    unsafe impl<
198            D: fidl::encoding::ResourceDialect,
199            T0: fidl::encoding::Encode<fidl::encoding::Array<Point, 2>, D>,
200        > fidl::encoding::Encode<InstanceAddLineRequest, D> for (T0,)
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::<InstanceAddLineRequest>(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            Ok(())
215        }
216    }
217
218    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
219        for InstanceAddLineRequest
220    {
221        #[inline(always)]
222        fn new_empty() -> Self {
223            Self { line: fidl::new_empty!(fidl::encoding::Array<Point, 2>, D) }
224        }
225
226        #[inline]
227        unsafe fn decode(
228            &mut self,
229            decoder: &mut fidl::encoding::Decoder<'_, D>,
230            offset: usize,
231            _depth: fidl::encoding::Depth,
232        ) -> fidl::Result<()> {
233            decoder.debug_check_bounds::<Self>(offset);
234            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
235            // Verify that padding bytes are zero.
236            // Copy from the buffer into the object.
237            unsafe {
238                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 32);
239            }
240            Ok(())
241        }
242    }
243
244    impl fidl::encoding::ValueTypeMarker for Point {
245        type Borrowed<'a> = &'a Self;
246        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
247            value
248        }
249    }
250
251    unsafe impl fidl::encoding::TypeMarker for Point {
252        type Owned = Self;
253
254        #[inline(always)]
255        fn inline_align(_context: fidl::encoding::Context) -> usize {
256            8
257        }
258
259        #[inline(always)]
260        fn inline_size(_context: fidl::encoding::Context) -> usize {
261            16
262        }
263        #[inline(always)]
264        fn encode_is_copy() -> bool {
265            true
266        }
267
268        #[inline(always)]
269        fn decode_is_copy() -> bool {
270            true
271        }
272    }
273
274    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Point, D> for &Point {
275        #[inline]
276        unsafe fn encode(
277            self,
278            encoder: &mut fidl::encoding::Encoder<'_, D>,
279            offset: usize,
280            _depth: fidl::encoding::Depth,
281        ) -> fidl::Result<()> {
282            encoder.debug_check_bounds::<Point>(offset);
283            unsafe {
284                // Copy the object into the buffer.
285                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
286                (buf_ptr as *mut Point).write_unaligned((self as *const Point).read());
287                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
288                // done second because the memcpy will write garbage to these bytes.
289            }
290            Ok(())
291        }
292    }
293    unsafe impl<
294            D: fidl::encoding::ResourceDialect,
295            T0: fidl::encoding::Encode<i64, D>,
296            T1: fidl::encoding::Encode<i64, D>,
297        > fidl::encoding::Encode<Point, D> for (T0, T1)
298    {
299        #[inline]
300        unsafe fn encode(
301            self,
302            encoder: &mut fidl::encoding::Encoder<'_, D>,
303            offset: usize,
304            depth: fidl::encoding::Depth,
305        ) -> fidl::Result<()> {
306            encoder.debug_check_bounds::<Point>(offset);
307            // Zero out padding regions. There's no need to apply masks
308            // because the unmasked parts will be overwritten by fields.
309            // Write the fields.
310            self.0.encode(encoder, offset + 0, depth)?;
311            self.1.encode(encoder, offset + 8, depth)?;
312            Ok(())
313        }
314    }
315
316    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Point {
317        #[inline(always)]
318        fn new_empty() -> Self {
319            Self { x: fidl::new_empty!(i64, D), y: fidl::new_empty!(i64, D) }
320        }
321
322        #[inline]
323        unsafe fn decode(
324            &mut self,
325            decoder: &mut fidl::encoding::Decoder<'_, D>,
326            offset: usize,
327            _depth: fidl::encoding::Depth,
328        ) -> fidl::Result<()> {
329            decoder.debug_check_bounds::<Self>(offset);
330            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
331            // Verify that padding bytes are zero.
332            // Copy from the buffer into the object.
333            unsafe {
334                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 16);
335            }
336            Ok(())
337        }
338    }
339}