fidl_examples_canvas_clientrequesteddraw__common/
fidl_examples_canvas_clientrequesteddraw__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, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
27pub struct InstanceAddLinesRequest {
28    pub lines: Vec<[Point; 2]>,
29}
30
31impl fidl::Persistable for InstanceAddLinesRequest {}
32
33/// A point in 2D space.
34#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
35#[repr(C)]
36pub struct Point {
37    pub x: i64,
38    pub y: i64,
39}
40
41impl fidl::Persistable for Point {}
42
43pub mod instance_ordinals {
44    pub const ADD_LINES: u64 = 0x5a82f0b30f970bd6;
45    pub const READY: u64 = 0x3458d7a668873150;
46    pub const ON_DRAWN: u64 = 0x25e6d8494623419a;
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 InstanceAddLinesRequest {
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 InstanceAddLinesRequest {
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            16
168        }
169    }
170
171    unsafe impl<D: fidl::encoding::ResourceDialect>
172        fidl::encoding::Encode<InstanceAddLinesRequest, D> for &InstanceAddLinesRequest
173    {
174        #[inline]
175        unsafe fn encode(
176            self,
177            encoder: &mut fidl::encoding::Encoder<'_, D>,
178            offset: usize,
179            _depth: fidl::encoding::Depth,
180        ) -> fidl::Result<()> {
181            encoder.debug_check_bounds::<InstanceAddLinesRequest>(offset);
182            // Delegate to tuple encoding.
183            fidl::encoding::Encode::<InstanceAddLinesRequest, D>::encode(
184                (
185                    <fidl::encoding::UnboundedVector<fidl::encoding::Array<Point, 2>> as fidl::encoding::ValueTypeMarker>::borrow(&self.lines),
186                ),
187                encoder, offset, _depth
188            )
189        }
190    }
191    unsafe impl<
192        D: fidl::encoding::ResourceDialect,
193        T0: fidl::encoding::Encode<fidl::encoding::UnboundedVector<fidl::encoding::Array<Point, 2>>, D>,
194    > fidl::encoding::Encode<InstanceAddLinesRequest, D> for (T0,)
195    {
196        #[inline]
197        unsafe fn encode(
198            self,
199            encoder: &mut fidl::encoding::Encoder<'_, D>,
200            offset: usize,
201            depth: fidl::encoding::Depth,
202        ) -> fidl::Result<()> {
203            encoder.debug_check_bounds::<InstanceAddLinesRequest>(offset);
204            // Zero out padding regions. There's no need to apply masks
205            // because the unmasked parts will be overwritten by fields.
206            // Write the fields.
207            self.0.encode(encoder, offset + 0, depth)?;
208            Ok(())
209        }
210    }
211
212    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
213        for InstanceAddLinesRequest
214    {
215        #[inline(always)]
216        fn new_empty() -> Self {
217            Self {
218                lines: fidl::new_empty!(
219                    fidl::encoding::UnboundedVector<fidl::encoding::Array<Point, 2>>,
220                    D
221                ),
222            }
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            // Verify that padding bytes are zero.
234            fidl::decode!(
235                fidl::encoding::UnboundedVector<fidl::encoding::Array<Point, 2>>,
236                D,
237                &mut self.lines,
238                decoder,
239                offset + 0,
240                _depth
241            )?;
242            Ok(())
243        }
244    }
245
246    impl fidl::encoding::ValueTypeMarker for Point {
247        type Borrowed<'a> = &'a Self;
248        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
249            value
250        }
251    }
252
253    unsafe impl fidl::encoding::TypeMarker for Point {
254        type Owned = Self;
255
256        #[inline(always)]
257        fn inline_align(_context: fidl::encoding::Context) -> usize {
258            8
259        }
260
261        #[inline(always)]
262        fn inline_size(_context: fidl::encoding::Context) -> usize {
263            16
264        }
265        #[inline(always)]
266        fn encode_is_copy() -> bool {
267            true
268        }
269
270        #[inline(always)]
271        fn decode_is_copy() -> bool {
272            true
273        }
274    }
275
276    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Point, D> for &Point {
277        #[inline]
278        unsafe fn encode(
279            self,
280            encoder: &mut fidl::encoding::Encoder<'_, D>,
281            offset: usize,
282            _depth: fidl::encoding::Depth,
283        ) -> fidl::Result<()> {
284            encoder.debug_check_bounds::<Point>(offset);
285            unsafe {
286                // Copy the object into the buffer.
287                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
288                (buf_ptr as *mut Point).write_unaligned((self as *const Point).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<i64, D>,
298        T1: fidl::encoding::Encode<i64, D>,
299    > fidl::encoding::Encode<Point, 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::<Point>(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 + 8, depth)?;
314            Ok(())
315        }
316    }
317
318    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Point {
319        #[inline(always)]
320        fn new_empty() -> Self {
321            Self { x: fidl::new_empty!(i64, D), y: fidl::new_empty!(i64, D) }
322        }
323
324        #[inline]
325        unsafe fn decode(
326            &mut self,
327            decoder: &mut fidl::encoding::Decoder<'_, D>,
328            offset: usize,
329            _depth: fidl::encoding::Depth,
330        ) -> fidl::Result<()> {
331            decoder.debug_check_bounds::<Self>(offset);
332            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
333            // Verify that padding bytes are zero.
334            // Copy from the buffer into the object.
335            unsafe {
336                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 16);
337            }
338            Ok(())
339        }
340    }
341}