fidl_fuchsia_ui_views__common/
fidl_fuchsia_ui_views__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)]
12pub enum AutoFocusError {
13    #[doc(hidden)]
14    __SourceBreaking { unknown_ordinal: u32 },
15}
16
17/// Pattern that matches an unknown `AutoFocusError` member.
18#[macro_export]
19macro_rules! AutoFocusErrorUnknown {
20    () => {
21        _
22    };
23}
24
25impl AutoFocusError {
26    #[inline]
27    pub fn from_primitive(prim: u32) -> Option<Self> {
28        match prim {
29            _ => None,
30        }
31    }
32
33    #[inline]
34    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
35        match prim {
36            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
37        }
38    }
39
40    #[inline]
41    pub fn unknown() -> Self {
42        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
43    }
44
45    #[inline]
46    pub const fn into_primitive(self) -> u32 {
47        match self {
48            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
49        }
50    }
51
52    #[inline]
53    pub fn is_unknown(&self) -> bool {
54        match self {
55            Self::__SourceBreaking { unknown_ordinal: _ } => true,
56        }
57    }
58}
59
60/// Problematic situations that occur on Focuser.RequestFocus.
61#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
62#[repr(u32)]
63pub enum Error {
64    /// Value returned when RequestFocus is denied.
65    Denied = 1,
66}
67
68impl Error {
69    #[inline]
70    pub fn from_primitive(prim: u32) -> Option<Self> {
71        match prim {
72            1 => Some(Self::Denied),
73            _ => None,
74        }
75    }
76
77    #[inline]
78    pub const fn into_primitive(self) -> u32 {
79        self as u32
80    }
81}
82
83/// A collection of error codes related to |ViewRefInstalled|.
84#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
85#[repr(u32)]
86pub enum ViewRefInstalledError {
87    /// The ViewRef being watched is invalid, or has become invalid.
88    InvalidViewRef = 1,
89}
90
91impl ViewRefInstalledError {
92    #[inline]
93    pub fn from_primitive(prim: u32) -> Option<Self> {
94        match prim {
95            1 => Some(Self::InvalidViewRef),
96            _ => None,
97        }
98    }
99
100    #[inline]
101    pub const fn into_primitive(self) -> u32 {
102        self as u32
103    }
104}
105
106#[derive(Clone, Debug, PartialEq)]
107pub struct ViewRefFocusedWatchResponse {
108    pub state: FocusState,
109}
110
111impl fidl::Persistable for ViewRefFocusedWatchResponse {}
112
113/// A ViewRef's state of focus.
114#[derive(Clone, Debug, Default, PartialEq)]
115pub struct FocusState {
116    /// Describes if a ViewRef has gained focus (true), or lost focus (false).
117    ///
118    /// Required field.
119    pub focused: Option<bool>,
120    #[doc(hidden)]
121    pub __source_breaking: fidl::marker::SourceBreaking,
122}
123
124impl fidl::Persistable for FocusState {}
125
126/// DO NOT USE - Retained for ABI stability in fuchsia.ui.scenic.Command
127#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
128pub enum Command {
129    Empty(i32),
130}
131
132impl Command {
133    #[inline]
134    pub fn ordinal(&self) -> u64 {
135        match *self {
136            Self::Empty(_) => 1,
137        }
138    }
139}
140
141impl fidl::Persistable for Command {}
142
143mod internal {
144    use super::*;
145    unsafe impl fidl::encoding::TypeMarker for AutoFocusError {
146        type Owned = Self;
147
148        #[inline(always)]
149        fn inline_align(_context: fidl::encoding::Context) -> usize {
150            std::mem::align_of::<u32>()
151        }
152
153        #[inline(always)]
154        fn inline_size(_context: fidl::encoding::Context) -> usize {
155            std::mem::size_of::<u32>()
156        }
157
158        #[inline(always)]
159        fn encode_is_copy() -> bool {
160            false
161        }
162
163        #[inline(always)]
164        fn decode_is_copy() -> bool {
165            false
166        }
167    }
168
169    impl fidl::encoding::ValueTypeMarker for AutoFocusError {
170        type Borrowed<'a> = Self;
171        #[inline(always)]
172        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
173            *value
174        }
175    }
176
177    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for AutoFocusError {
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::<Self>(offset);
186            encoder.write_num(self.into_primitive(), offset);
187            Ok(())
188        }
189    }
190
191    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for AutoFocusError {
192        #[inline(always)]
193        fn new_empty() -> Self {
194            Self::unknown()
195        }
196
197        #[inline]
198        unsafe fn decode(
199            &mut self,
200            decoder: &mut fidl::encoding::Decoder<'_, D>,
201            offset: usize,
202            _depth: fidl::encoding::Depth,
203        ) -> fidl::Result<()> {
204            decoder.debug_check_bounds::<Self>(offset);
205            let prim = decoder.read_num::<u32>(offset);
206
207            *self = Self::from_primitive_allow_unknown(prim);
208            Ok(())
209        }
210    }
211    unsafe impl fidl::encoding::TypeMarker for Error {
212        type Owned = Self;
213
214        #[inline(always)]
215        fn inline_align(_context: fidl::encoding::Context) -> usize {
216            std::mem::align_of::<u32>()
217        }
218
219        #[inline(always)]
220        fn inline_size(_context: fidl::encoding::Context) -> usize {
221            std::mem::size_of::<u32>()
222        }
223
224        #[inline(always)]
225        fn encode_is_copy() -> bool {
226            true
227        }
228
229        #[inline(always)]
230        fn decode_is_copy() -> bool {
231            false
232        }
233    }
234
235    impl fidl::encoding::ValueTypeMarker for Error {
236        type Borrowed<'a> = Self;
237        #[inline(always)]
238        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
239            *value
240        }
241    }
242
243    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
244        #[inline]
245        unsafe fn encode(
246            self,
247            encoder: &mut fidl::encoding::Encoder<'_, D>,
248            offset: usize,
249            _depth: fidl::encoding::Depth,
250        ) -> fidl::Result<()> {
251            encoder.debug_check_bounds::<Self>(offset);
252            encoder.write_num(self.into_primitive(), offset);
253            Ok(())
254        }
255    }
256
257    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
258        #[inline(always)]
259        fn new_empty() -> Self {
260            Self::Denied
261        }
262
263        #[inline]
264        unsafe fn decode(
265            &mut self,
266            decoder: &mut fidl::encoding::Decoder<'_, D>,
267            offset: usize,
268            _depth: fidl::encoding::Depth,
269        ) -> fidl::Result<()> {
270            decoder.debug_check_bounds::<Self>(offset);
271            let prim = decoder.read_num::<u32>(offset);
272
273            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
274            Ok(())
275        }
276    }
277    unsafe impl fidl::encoding::TypeMarker for ViewRefInstalledError {
278        type Owned = Self;
279
280        #[inline(always)]
281        fn inline_align(_context: fidl::encoding::Context) -> usize {
282            std::mem::align_of::<u32>()
283        }
284
285        #[inline(always)]
286        fn inline_size(_context: fidl::encoding::Context) -> usize {
287            std::mem::size_of::<u32>()
288        }
289
290        #[inline(always)]
291        fn encode_is_copy() -> bool {
292            true
293        }
294
295        #[inline(always)]
296        fn decode_is_copy() -> bool {
297            false
298        }
299    }
300
301    impl fidl::encoding::ValueTypeMarker for ViewRefInstalledError {
302        type Borrowed<'a> = Self;
303        #[inline(always)]
304        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
305            *value
306        }
307    }
308
309    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
310        for ViewRefInstalledError
311    {
312        #[inline]
313        unsafe fn encode(
314            self,
315            encoder: &mut fidl::encoding::Encoder<'_, D>,
316            offset: usize,
317            _depth: fidl::encoding::Depth,
318        ) -> fidl::Result<()> {
319            encoder.debug_check_bounds::<Self>(offset);
320            encoder.write_num(self.into_primitive(), offset);
321            Ok(())
322        }
323    }
324
325    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ViewRefInstalledError {
326        #[inline(always)]
327        fn new_empty() -> Self {
328            Self::InvalidViewRef
329        }
330
331        #[inline]
332        unsafe fn decode(
333            &mut self,
334            decoder: &mut fidl::encoding::Decoder<'_, D>,
335            offset: usize,
336            _depth: fidl::encoding::Depth,
337        ) -> fidl::Result<()> {
338            decoder.debug_check_bounds::<Self>(offset);
339            let prim = decoder.read_num::<u32>(offset);
340
341            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
342            Ok(())
343        }
344    }
345
346    impl fidl::encoding::ValueTypeMarker for ViewRefFocusedWatchResponse {
347        type Borrowed<'a> = &'a Self;
348        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
349            value
350        }
351    }
352
353    unsafe impl fidl::encoding::TypeMarker for ViewRefFocusedWatchResponse {
354        type Owned = Self;
355
356        #[inline(always)]
357        fn inline_align(_context: fidl::encoding::Context) -> usize {
358            8
359        }
360
361        #[inline(always)]
362        fn inline_size(_context: fidl::encoding::Context) -> usize {
363            16
364        }
365    }
366
367    unsafe impl<D: fidl::encoding::ResourceDialect>
368        fidl::encoding::Encode<ViewRefFocusedWatchResponse, D> for &ViewRefFocusedWatchResponse
369    {
370        #[inline]
371        unsafe fn encode(
372            self,
373            encoder: &mut fidl::encoding::Encoder<'_, D>,
374            offset: usize,
375            _depth: fidl::encoding::Depth,
376        ) -> fidl::Result<()> {
377            encoder.debug_check_bounds::<ViewRefFocusedWatchResponse>(offset);
378            // Delegate to tuple encoding.
379            fidl::encoding::Encode::<ViewRefFocusedWatchResponse, D>::encode(
380                (<FocusState as fidl::encoding::ValueTypeMarker>::borrow(&self.state),),
381                encoder,
382                offset,
383                _depth,
384            )
385        }
386    }
387    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<FocusState, D>>
388        fidl::encoding::Encode<ViewRefFocusedWatchResponse, D> for (T0,)
389    {
390        #[inline]
391        unsafe fn encode(
392            self,
393            encoder: &mut fidl::encoding::Encoder<'_, D>,
394            offset: usize,
395            depth: fidl::encoding::Depth,
396        ) -> fidl::Result<()> {
397            encoder.debug_check_bounds::<ViewRefFocusedWatchResponse>(offset);
398            // Zero out padding regions. There's no need to apply masks
399            // because the unmasked parts will be overwritten by fields.
400            // Write the fields.
401            self.0.encode(encoder, offset + 0, depth)?;
402            Ok(())
403        }
404    }
405
406    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
407        for ViewRefFocusedWatchResponse
408    {
409        #[inline(always)]
410        fn new_empty() -> Self {
411            Self { state: fidl::new_empty!(FocusState, D) }
412        }
413
414        #[inline]
415        unsafe fn decode(
416            &mut self,
417            decoder: &mut fidl::encoding::Decoder<'_, D>,
418            offset: usize,
419            _depth: fidl::encoding::Depth,
420        ) -> fidl::Result<()> {
421            decoder.debug_check_bounds::<Self>(offset);
422            // Verify that padding bytes are zero.
423            fidl::decode!(FocusState, D, &mut self.state, decoder, offset + 0, _depth)?;
424            Ok(())
425        }
426    }
427
428    impl FocusState {
429        #[inline(always)]
430        fn max_ordinal_present(&self) -> u64 {
431            if let Some(_) = self.focused {
432                return 1;
433            }
434            0
435        }
436    }
437
438    impl fidl::encoding::ValueTypeMarker for FocusState {
439        type Borrowed<'a> = &'a Self;
440        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
441            value
442        }
443    }
444
445    unsafe impl fidl::encoding::TypeMarker for FocusState {
446        type Owned = Self;
447
448        #[inline(always)]
449        fn inline_align(_context: fidl::encoding::Context) -> usize {
450            8
451        }
452
453        #[inline(always)]
454        fn inline_size(_context: fidl::encoding::Context) -> usize {
455            16
456        }
457    }
458
459    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<FocusState, D>
460        for &FocusState
461    {
462        unsafe fn encode(
463            self,
464            encoder: &mut fidl::encoding::Encoder<'_, D>,
465            offset: usize,
466            mut depth: fidl::encoding::Depth,
467        ) -> fidl::Result<()> {
468            encoder.debug_check_bounds::<FocusState>(offset);
469            // Vector header
470            let max_ordinal: u64 = self.max_ordinal_present();
471            encoder.write_num(max_ordinal, offset);
472            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
473            // Calling encoder.out_of_line_offset(0) is not allowed.
474            if max_ordinal == 0 {
475                return Ok(());
476            }
477            depth.increment()?;
478            let envelope_size = 8;
479            let bytes_len = max_ordinal as usize * envelope_size;
480            #[allow(unused_variables)]
481            let offset = encoder.out_of_line_offset(bytes_len);
482            let mut _prev_end_offset: usize = 0;
483            if 1 > max_ordinal {
484                return Ok(());
485            }
486
487            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
488            // are envelope_size bytes.
489            let cur_offset: usize = (1 - 1) * envelope_size;
490
491            // Zero reserved fields.
492            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
493
494            // Safety:
495            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
496            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
497            //   envelope_size bytes, there is always sufficient room.
498            fidl::encoding::encode_in_envelope_optional::<bool, D>(
499                self.focused.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
500                encoder,
501                offset + cur_offset,
502                depth,
503            )?;
504
505            _prev_end_offset = cur_offset + envelope_size;
506
507            Ok(())
508        }
509    }
510
511    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for FocusState {
512        #[inline(always)]
513        fn new_empty() -> Self {
514            Self::default()
515        }
516
517        unsafe fn decode(
518            &mut self,
519            decoder: &mut fidl::encoding::Decoder<'_, D>,
520            offset: usize,
521            mut depth: fidl::encoding::Depth,
522        ) -> fidl::Result<()> {
523            decoder.debug_check_bounds::<Self>(offset);
524            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
525                None => return Err(fidl::Error::NotNullable),
526                Some(len) => len,
527            };
528            // Calling decoder.out_of_line_offset(0) is not allowed.
529            if len == 0 {
530                return Ok(());
531            };
532            depth.increment()?;
533            let envelope_size = 8;
534            let bytes_len = len * envelope_size;
535            let offset = decoder.out_of_line_offset(bytes_len)?;
536            // Decode the envelope for each type.
537            let mut _next_ordinal_to_read = 0;
538            let mut next_offset = offset;
539            let end_offset = offset + bytes_len;
540            _next_ordinal_to_read += 1;
541            if next_offset >= end_offset {
542                return Ok(());
543            }
544
545            // Decode unknown envelopes for gaps in ordinals.
546            while _next_ordinal_to_read < 1 {
547                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
548                _next_ordinal_to_read += 1;
549                next_offset += envelope_size;
550            }
551
552            let next_out_of_line = decoder.next_out_of_line();
553            let handles_before = decoder.remaining_handles();
554            if let Some((inlined, num_bytes, num_handles)) =
555                fidl::encoding::decode_envelope_header(decoder, next_offset)?
556            {
557                let member_inline_size =
558                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
559                if inlined != (member_inline_size <= 4) {
560                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
561                }
562                let inner_offset;
563                let mut inner_depth = depth.clone();
564                if inlined {
565                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
566                    inner_offset = next_offset;
567                } else {
568                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
569                    inner_depth.increment()?;
570                }
571                let val_ref = self.focused.get_or_insert_with(|| fidl::new_empty!(bool, D));
572                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
573                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
574                {
575                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
576                }
577                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
578                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
579                }
580            }
581
582            next_offset += envelope_size;
583
584            // Decode the remaining unknown envelopes.
585            while next_offset < end_offset {
586                _next_ordinal_to_read += 1;
587                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
588                next_offset += envelope_size;
589            }
590
591            Ok(())
592        }
593    }
594
595    impl fidl::encoding::ValueTypeMarker for Command {
596        type Borrowed<'a> = &'a Self;
597        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
598            value
599        }
600    }
601
602    unsafe impl fidl::encoding::TypeMarker for Command {
603        type Owned = Self;
604
605        #[inline(always)]
606        fn inline_align(_context: fidl::encoding::Context) -> usize {
607            8
608        }
609
610        #[inline(always)]
611        fn inline_size(_context: fidl::encoding::Context) -> usize {
612            16
613        }
614    }
615
616    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Command, D> for &Command {
617        #[inline]
618        unsafe fn encode(
619            self,
620            encoder: &mut fidl::encoding::Encoder<'_, D>,
621            offset: usize,
622            _depth: fidl::encoding::Depth,
623        ) -> fidl::Result<()> {
624            encoder.debug_check_bounds::<Command>(offset);
625            encoder.write_num::<u64>(self.ordinal(), offset);
626            match self {
627                Command::Empty(ref val) => fidl::encoding::encode_in_envelope::<i32, D>(
628                    <i32 as fidl::encoding::ValueTypeMarker>::borrow(val),
629                    encoder,
630                    offset + 8,
631                    _depth,
632                ),
633            }
634        }
635    }
636
637    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Command {
638        #[inline(always)]
639        fn new_empty() -> Self {
640            Self::Empty(fidl::new_empty!(i32, D))
641        }
642
643        #[inline]
644        unsafe fn decode(
645            &mut self,
646            decoder: &mut fidl::encoding::Decoder<'_, D>,
647            offset: usize,
648            mut depth: fidl::encoding::Depth,
649        ) -> fidl::Result<()> {
650            decoder.debug_check_bounds::<Self>(offset);
651            #[allow(unused_variables)]
652            let next_out_of_line = decoder.next_out_of_line();
653            let handles_before = decoder.remaining_handles();
654            let (ordinal, inlined, num_bytes, num_handles) =
655                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
656
657            let member_inline_size = match ordinal {
658                1 => <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
659                _ => return Err(fidl::Error::UnknownUnionTag),
660            };
661
662            if inlined != (member_inline_size <= 4) {
663                return Err(fidl::Error::InvalidInlineBitInEnvelope);
664            }
665            let _inner_offset;
666            if inlined {
667                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
668                _inner_offset = offset + 8;
669            } else {
670                depth.increment()?;
671                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
672            }
673            match ordinal {
674                1 => {
675                    #[allow(irrefutable_let_patterns)]
676                    if let Command::Empty(_) = self {
677                        // Do nothing, read the value into the object
678                    } else {
679                        // Initialize `self` to the right variant
680                        *self = Command::Empty(fidl::new_empty!(i32, D));
681                    }
682                    #[allow(irrefutable_let_patterns)]
683                    if let Command::Empty(ref mut val) = self {
684                        fidl::decode!(i32, D, val, decoder, _inner_offset, depth)?;
685                    } else {
686                        unreachable!()
687                    }
688                }
689                ordinal => panic!("unexpected ordinal {:?}", ordinal),
690            }
691            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
692                return Err(fidl::Error::InvalidNumBytesInEnvelope);
693            }
694            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
695                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
696            }
697            Ok(())
698        }
699    }
700}