fidl_examples_canvas_baseline__common/
fidl_examples_canvas_baseline__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
44pub mod instance_ordinals {
45    pub const ADD_LINE: u64 = 0x3f5b799d54b4aa0;
46    pub const ON_DRAWN: u64 = 0x2eeaa5f17200458d;
47}
48
49mod internal {
50    use super::*;
51
52    impl fidl::encoding::ValueTypeMarker for BoundingBox {
53        type Borrowed<'a> = &'a Self;
54        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
55            value
56        }
57    }
58
59    unsafe impl fidl::encoding::TypeMarker for BoundingBox {
60        type Owned = Self;
61
62        #[inline(always)]
63        fn inline_align(_context: fidl::encoding::Context) -> usize {
64            8
65        }
66
67        #[inline(always)]
68        fn inline_size(_context: fidl::encoding::Context) -> usize {
69            32
70        }
71        #[inline(always)]
72        fn encode_is_copy() -> bool {
73            true
74        }
75
76        #[inline(always)]
77        fn decode_is_copy() -> bool {
78            true
79        }
80    }
81
82    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<BoundingBox, D>
83        for &BoundingBox
84    {
85        #[inline]
86        unsafe fn encode(
87            self,
88            encoder: &mut fidl::encoding::Encoder<'_, D>,
89            offset: usize,
90            _depth: fidl::encoding::Depth,
91        ) -> fidl::Result<()> {
92            encoder.debug_check_bounds::<BoundingBox>(offset);
93            unsafe {
94                // Copy the object into the buffer.
95                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
96                (buf_ptr as *mut BoundingBox).write_unaligned((self as *const BoundingBox).read());
97                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
98                // done second because the memcpy will write garbage to these bytes.
99            }
100            Ok(())
101        }
102    }
103    unsafe impl<
104            D: fidl::encoding::ResourceDialect,
105            T0: fidl::encoding::Encode<Point, D>,
106            T1: fidl::encoding::Encode<Point, D>,
107        > fidl::encoding::Encode<BoundingBox, D> for (T0, T1)
108    {
109        #[inline]
110        unsafe fn encode(
111            self,
112            encoder: &mut fidl::encoding::Encoder<'_, D>,
113            offset: usize,
114            depth: fidl::encoding::Depth,
115        ) -> fidl::Result<()> {
116            encoder.debug_check_bounds::<BoundingBox>(offset);
117            // Zero out padding regions. There's no need to apply masks
118            // because the unmasked parts will be overwritten by fields.
119            // Write the fields.
120            self.0.encode(encoder, offset + 0, depth)?;
121            self.1.encode(encoder, offset + 16, depth)?;
122            Ok(())
123        }
124    }
125
126    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BoundingBox {
127        #[inline(always)]
128        fn new_empty() -> Self {
129            Self { top_left: fidl::new_empty!(Point, D), bottom_right: fidl::new_empty!(Point, D) }
130        }
131
132        #[inline]
133        unsafe fn decode(
134            &mut self,
135            decoder: &mut fidl::encoding::Decoder<'_, D>,
136            offset: usize,
137            _depth: fidl::encoding::Depth,
138        ) -> fidl::Result<()> {
139            decoder.debug_check_bounds::<Self>(offset);
140            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
141            // Verify that padding bytes are zero.
142            // Copy from the buffer into the object.
143            unsafe {
144                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 32);
145            }
146            Ok(())
147        }
148    }
149
150    impl fidl::encoding::ValueTypeMarker for InstanceAddLineRequest {
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 InstanceAddLineRequest {
158        type Owned = Self;
159
160        #[inline(always)]
161        fn inline_align(_context: fidl::encoding::Context) -> usize {
162            8
163        }
164
165        #[inline(always)]
166        fn inline_size(_context: fidl::encoding::Context) -> usize {
167            32
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>
181        fidl::encoding::Encode<InstanceAddLineRequest, D> for &InstanceAddLineRequest
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::<InstanceAddLineRequest>(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 InstanceAddLineRequest)
195                    .write_unaligned((self as *const InstanceAddLineRequest).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<fidl::encoding::Array<Point, 2>, D>,
205        > fidl::encoding::Encode<InstanceAddLineRequest, D> for (T0,)
206    {
207        #[inline]
208        unsafe fn encode(
209            self,
210            encoder: &mut fidl::encoding::Encoder<'_, D>,
211            offset: usize,
212            depth: fidl::encoding::Depth,
213        ) -> fidl::Result<()> {
214            encoder.debug_check_bounds::<InstanceAddLineRequest>(offset);
215            // Zero out padding regions. There's no need to apply masks
216            // because the unmasked parts will be overwritten by fields.
217            // Write the fields.
218            self.0.encode(encoder, offset + 0, depth)?;
219            Ok(())
220        }
221    }
222
223    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
224        for InstanceAddLineRequest
225    {
226        #[inline(always)]
227        fn new_empty() -> Self {
228            Self { line: fidl::new_empty!(fidl::encoding::Array<Point, 2>, 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, 32);
244            }
245            Ok(())
246        }
247    }
248
249    impl fidl::encoding::ValueTypeMarker for Point {
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 Point {
257        type Owned = Self;
258
259        #[inline(always)]
260        fn inline_align(_context: fidl::encoding::Context) -> usize {
261            8
262        }
263
264        #[inline(always)]
265        fn inline_size(_context: fidl::encoding::Context) -> usize {
266            16
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> fidl::encoding::Encode<Point, D> for &Point {
280        #[inline]
281        unsafe fn encode(
282            self,
283            encoder: &mut fidl::encoding::Encoder<'_, D>,
284            offset: usize,
285            _depth: fidl::encoding::Depth,
286        ) -> fidl::Result<()> {
287            encoder.debug_check_bounds::<Point>(offset);
288            unsafe {
289                // Copy the object into the buffer.
290                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
291                (buf_ptr as *mut Point).write_unaligned((self as *const Point).read());
292                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
293                // done second because the memcpy will write garbage to these bytes.
294            }
295            Ok(())
296        }
297    }
298    unsafe impl<
299            D: fidl::encoding::ResourceDialect,
300            T0: fidl::encoding::Encode<i64, D>,
301            T1: fidl::encoding::Encode<i64, D>,
302        > fidl::encoding::Encode<Point, D> for (T0, T1)
303    {
304        #[inline]
305        unsafe fn encode(
306            self,
307            encoder: &mut fidl::encoding::Encoder<'_, D>,
308            offset: usize,
309            depth: fidl::encoding::Depth,
310        ) -> fidl::Result<()> {
311            encoder.debug_check_bounds::<Point>(offset);
312            // Zero out padding regions. There's no need to apply masks
313            // because the unmasked parts will be overwritten by fields.
314            // Write the fields.
315            self.0.encode(encoder, offset + 0, depth)?;
316            self.1.encode(encoder, offset + 8, depth)?;
317            Ok(())
318        }
319    }
320
321    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Point {
322        #[inline(always)]
323        fn new_empty() -> Self {
324            Self { x: fidl::new_empty!(i64, D), y: fidl::new_empty!(i64, D) }
325        }
326
327        #[inline]
328        unsafe fn decode(
329            &mut self,
330            decoder: &mut fidl::encoding::Decoder<'_, D>,
331            offset: usize,
332            _depth: fidl::encoding::Depth,
333        ) -> fidl::Result<()> {
334            decoder.debug_check_bounds::<Self>(offset);
335            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
336            // Verify that padding bytes are zero.
337            // Copy from the buffer into the object.
338            unsafe {
339                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 16);
340            }
341            Ok(())
342        }
343    }
344}