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
143pub mod focuser_ordinals {
144    pub const REQUEST_FOCUS: u64 = 0x559067eb07097d5;
145    pub const SET_AUTO_FOCUS: u64 = 0x480feb5856329509;
146}
147
148pub mod view_ordinals {
149    pub const PRESENT: u64 = 0x6e98ebc6c9de6d9e;
150}
151
152pub mod view_ref_focused_ordinals {
153    pub const WATCH: u64 = 0x3c5e51096d9299b5;
154}
155
156pub mod view_ref_installed_ordinals {
157    pub const WATCH: u64 = 0x7ddec2f4ca687971;
158}
159
160mod internal {
161    use super::*;
162    unsafe impl fidl::encoding::TypeMarker for AutoFocusError {
163        type Owned = Self;
164
165        #[inline(always)]
166        fn inline_align(_context: fidl::encoding::Context) -> usize {
167            std::mem::align_of::<u32>()
168        }
169
170        #[inline(always)]
171        fn inline_size(_context: fidl::encoding::Context) -> usize {
172            std::mem::size_of::<u32>()
173        }
174
175        #[inline(always)]
176        fn encode_is_copy() -> bool {
177            false
178        }
179
180        #[inline(always)]
181        fn decode_is_copy() -> bool {
182            false
183        }
184    }
185
186    impl fidl::encoding::ValueTypeMarker for AutoFocusError {
187        type Borrowed<'a> = Self;
188        #[inline(always)]
189        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
190            *value
191        }
192    }
193
194    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for AutoFocusError {
195        #[inline]
196        unsafe fn encode(
197            self,
198            encoder: &mut fidl::encoding::Encoder<'_, D>,
199            offset: usize,
200            _depth: fidl::encoding::Depth,
201        ) -> fidl::Result<()> {
202            encoder.debug_check_bounds::<Self>(offset);
203            encoder.write_num(self.into_primitive(), offset);
204            Ok(())
205        }
206    }
207
208    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for AutoFocusError {
209        #[inline(always)]
210        fn new_empty() -> Self {
211            Self::unknown()
212        }
213
214        #[inline]
215        unsafe fn decode(
216            &mut self,
217            decoder: &mut fidl::encoding::Decoder<'_, D>,
218            offset: usize,
219            _depth: fidl::encoding::Depth,
220        ) -> fidl::Result<()> {
221            decoder.debug_check_bounds::<Self>(offset);
222            let prim = decoder.read_num::<u32>(offset);
223
224            *self = Self::from_primitive_allow_unknown(prim);
225            Ok(())
226        }
227    }
228    unsafe impl fidl::encoding::TypeMarker for Error {
229        type Owned = Self;
230
231        #[inline(always)]
232        fn inline_align(_context: fidl::encoding::Context) -> usize {
233            std::mem::align_of::<u32>()
234        }
235
236        #[inline(always)]
237        fn inline_size(_context: fidl::encoding::Context) -> usize {
238            std::mem::size_of::<u32>()
239        }
240
241        #[inline(always)]
242        fn encode_is_copy() -> bool {
243            true
244        }
245
246        #[inline(always)]
247        fn decode_is_copy() -> bool {
248            false
249        }
250    }
251
252    impl fidl::encoding::ValueTypeMarker for Error {
253        type Borrowed<'a> = Self;
254        #[inline(always)]
255        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
256            *value
257        }
258    }
259
260    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
261        #[inline]
262        unsafe fn encode(
263            self,
264            encoder: &mut fidl::encoding::Encoder<'_, D>,
265            offset: usize,
266            _depth: fidl::encoding::Depth,
267        ) -> fidl::Result<()> {
268            encoder.debug_check_bounds::<Self>(offset);
269            encoder.write_num(self.into_primitive(), offset);
270            Ok(())
271        }
272    }
273
274    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
275        #[inline(always)]
276        fn new_empty() -> Self {
277            Self::Denied
278        }
279
280        #[inline]
281        unsafe fn decode(
282            &mut self,
283            decoder: &mut fidl::encoding::Decoder<'_, D>,
284            offset: usize,
285            _depth: fidl::encoding::Depth,
286        ) -> fidl::Result<()> {
287            decoder.debug_check_bounds::<Self>(offset);
288            let prim = decoder.read_num::<u32>(offset);
289
290            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
291            Ok(())
292        }
293    }
294    unsafe impl fidl::encoding::TypeMarker for ViewRefInstalledError {
295        type Owned = Self;
296
297        #[inline(always)]
298        fn inline_align(_context: fidl::encoding::Context) -> usize {
299            std::mem::align_of::<u32>()
300        }
301
302        #[inline(always)]
303        fn inline_size(_context: fidl::encoding::Context) -> usize {
304            std::mem::size_of::<u32>()
305        }
306
307        #[inline(always)]
308        fn encode_is_copy() -> bool {
309            true
310        }
311
312        #[inline(always)]
313        fn decode_is_copy() -> bool {
314            false
315        }
316    }
317
318    impl fidl::encoding::ValueTypeMarker for ViewRefInstalledError {
319        type Borrowed<'a> = Self;
320        #[inline(always)]
321        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
322            *value
323        }
324    }
325
326    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
327        for ViewRefInstalledError
328    {
329        #[inline]
330        unsafe fn encode(
331            self,
332            encoder: &mut fidl::encoding::Encoder<'_, D>,
333            offset: usize,
334            _depth: fidl::encoding::Depth,
335        ) -> fidl::Result<()> {
336            encoder.debug_check_bounds::<Self>(offset);
337            encoder.write_num(self.into_primitive(), offset);
338            Ok(())
339        }
340    }
341
342    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ViewRefInstalledError {
343        #[inline(always)]
344        fn new_empty() -> Self {
345            Self::InvalidViewRef
346        }
347
348        #[inline]
349        unsafe fn decode(
350            &mut self,
351            decoder: &mut fidl::encoding::Decoder<'_, D>,
352            offset: usize,
353            _depth: fidl::encoding::Depth,
354        ) -> fidl::Result<()> {
355            decoder.debug_check_bounds::<Self>(offset);
356            let prim = decoder.read_num::<u32>(offset);
357
358            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
359            Ok(())
360        }
361    }
362
363    impl fidl::encoding::ValueTypeMarker for ViewRefFocusedWatchResponse {
364        type Borrowed<'a> = &'a Self;
365        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
366            value
367        }
368    }
369
370    unsafe impl fidl::encoding::TypeMarker for ViewRefFocusedWatchResponse {
371        type Owned = Self;
372
373        #[inline(always)]
374        fn inline_align(_context: fidl::encoding::Context) -> usize {
375            8
376        }
377
378        #[inline(always)]
379        fn inline_size(_context: fidl::encoding::Context) -> usize {
380            16
381        }
382    }
383
384    unsafe impl<D: fidl::encoding::ResourceDialect>
385        fidl::encoding::Encode<ViewRefFocusedWatchResponse, D> for &ViewRefFocusedWatchResponse
386    {
387        #[inline]
388        unsafe fn encode(
389            self,
390            encoder: &mut fidl::encoding::Encoder<'_, D>,
391            offset: usize,
392            _depth: fidl::encoding::Depth,
393        ) -> fidl::Result<()> {
394            encoder.debug_check_bounds::<ViewRefFocusedWatchResponse>(offset);
395            // Delegate to tuple encoding.
396            fidl::encoding::Encode::<ViewRefFocusedWatchResponse, D>::encode(
397                (<FocusState as fidl::encoding::ValueTypeMarker>::borrow(&self.state),),
398                encoder,
399                offset,
400                _depth,
401            )
402        }
403    }
404    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<FocusState, D>>
405        fidl::encoding::Encode<ViewRefFocusedWatchResponse, D> for (T0,)
406    {
407        #[inline]
408        unsafe fn encode(
409            self,
410            encoder: &mut fidl::encoding::Encoder<'_, D>,
411            offset: usize,
412            depth: fidl::encoding::Depth,
413        ) -> fidl::Result<()> {
414            encoder.debug_check_bounds::<ViewRefFocusedWatchResponse>(offset);
415            // Zero out padding regions. There's no need to apply masks
416            // because the unmasked parts will be overwritten by fields.
417            // Write the fields.
418            self.0.encode(encoder, offset + 0, depth)?;
419            Ok(())
420        }
421    }
422
423    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
424        for ViewRefFocusedWatchResponse
425    {
426        #[inline(always)]
427        fn new_empty() -> Self {
428            Self { state: fidl::new_empty!(FocusState, D) }
429        }
430
431        #[inline]
432        unsafe fn decode(
433            &mut self,
434            decoder: &mut fidl::encoding::Decoder<'_, D>,
435            offset: usize,
436            _depth: fidl::encoding::Depth,
437        ) -> fidl::Result<()> {
438            decoder.debug_check_bounds::<Self>(offset);
439            // Verify that padding bytes are zero.
440            fidl::decode!(FocusState, D, &mut self.state, decoder, offset + 0, _depth)?;
441            Ok(())
442        }
443    }
444
445    impl FocusState {
446        #[inline(always)]
447        fn max_ordinal_present(&self) -> u64 {
448            if let Some(_) = self.focused {
449                return 1;
450            }
451            0
452        }
453    }
454
455    impl fidl::encoding::ValueTypeMarker for FocusState {
456        type Borrowed<'a> = &'a Self;
457        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
458            value
459        }
460    }
461
462    unsafe impl fidl::encoding::TypeMarker for FocusState {
463        type Owned = Self;
464
465        #[inline(always)]
466        fn inline_align(_context: fidl::encoding::Context) -> usize {
467            8
468        }
469
470        #[inline(always)]
471        fn inline_size(_context: fidl::encoding::Context) -> usize {
472            16
473        }
474    }
475
476    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<FocusState, D>
477        for &FocusState
478    {
479        unsafe fn encode(
480            self,
481            encoder: &mut fidl::encoding::Encoder<'_, D>,
482            offset: usize,
483            mut depth: fidl::encoding::Depth,
484        ) -> fidl::Result<()> {
485            encoder.debug_check_bounds::<FocusState>(offset);
486            // Vector header
487            let max_ordinal: u64 = self.max_ordinal_present();
488            encoder.write_num(max_ordinal, offset);
489            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
490            // Calling encoder.out_of_line_offset(0) is not allowed.
491            if max_ordinal == 0 {
492                return Ok(());
493            }
494            depth.increment()?;
495            let envelope_size = 8;
496            let bytes_len = max_ordinal as usize * envelope_size;
497            #[allow(unused_variables)]
498            let offset = encoder.out_of_line_offset(bytes_len);
499            let mut _prev_end_offset: usize = 0;
500            if 1 > max_ordinal {
501                return Ok(());
502            }
503
504            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
505            // are envelope_size bytes.
506            let cur_offset: usize = (1 - 1) * envelope_size;
507
508            // Zero reserved fields.
509            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
510
511            // Safety:
512            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
513            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
514            //   envelope_size bytes, there is always sufficient room.
515            fidl::encoding::encode_in_envelope_optional::<bool, D>(
516                self.focused.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
517                encoder,
518                offset + cur_offset,
519                depth,
520            )?;
521
522            _prev_end_offset = cur_offset + envelope_size;
523
524            Ok(())
525        }
526    }
527
528    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for FocusState {
529        #[inline(always)]
530        fn new_empty() -> Self {
531            Self::default()
532        }
533
534        unsafe fn decode(
535            &mut self,
536            decoder: &mut fidl::encoding::Decoder<'_, D>,
537            offset: usize,
538            mut depth: fidl::encoding::Depth,
539        ) -> fidl::Result<()> {
540            decoder.debug_check_bounds::<Self>(offset);
541            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
542                None => return Err(fidl::Error::NotNullable),
543                Some(len) => len,
544            };
545            // Calling decoder.out_of_line_offset(0) is not allowed.
546            if len == 0 {
547                return Ok(());
548            };
549            depth.increment()?;
550            let envelope_size = 8;
551            let bytes_len = len * envelope_size;
552            let offset = decoder.out_of_line_offset(bytes_len)?;
553            // Decode the envelope for each type.
554            let mut _next_ordinal_to_read = 0;
555            let mut next_offset = offset;
556            let end_offset = offset + bytes_len;
557            _next_ordinal_to_read += 1;
558            if next_offset >= end_offset {
559                return Ok(());
560            }
561
562            // Decode unknown envelopes for gaps in ordinals.
563            while _next_ordinal_to_read < 1 {
564                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
565                _next_ordinal_to_read += 1;
566                next_offset += envelope_size;
567            }
568
569            let next_out_of_line = decoder.next_out_of_line();
570            let handles_before = decoder.remaining_handles();
571            if let Some((inlined, num_bytes, num_handles)) =
572                fidl::encoding::decode_envelope_header(decoder, next_offset)?
573            {
574                let member_inline_size =
575                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
576                if inlined != (member_inline_size <= 4) {
577                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
578                }
579                let inner_offset;
580                let mut inner_depth = depth.clone();
581                if inlined {
582                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
583                    inner_offset = next_offset;
584                } else {
585                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
586                    inner_depth.increment()?;
587                }
588                let val_ref = self.focused.get_or_insert_with(|| fidl::new_empty!(bool, D));
589                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
590                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
591                {
592                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
593                }
594                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
595                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
596                }
597            }
598
599            next_offset += envelope_size;
600
601            // Decode the remaining unknown envelopes.
602            while next_offset < end_offset {
603                _next_ordinal_to_read += 1;
604                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
605                next_offset += envelope_size;
606            }
607
608            Ok(())
609        }
610    }
611
612    impl fidl::encoding::ValueTypeMarker for Command {
613        type Borrowed<'a> = &'a Self;
614        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
615            value
616        }
617    }
618
619    unsafe impl fidl::encoding::TypeMarker for Command {
620        type Owned = Self;
621
622        #[inline(always)]
623        fn inline_align(_context: fidl::encoding::Context) -> usize {
624            8
625        }
626
627        #[inline(always)]
628        fn inline_size(_context: fidl::encoding::Context) -> usize {
629            16
630        }
631    }
632
633    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Command, D> for &Command {
634        #[inline]
635        unsafe fn encode(
636            self,
637            encoder: &mut fidl::encoding::Encoder<'_, D>,
638            offset: usize,
639            _depth: fidl::encoding::Depth,
640        ) -> fidl::Result<()> {
641            encoder.debug_check_bounds::<Command>(offset);
642            encoder.write_num::<u64>(self.ordinal(), offset);
643            match self {
644                Command::Empty(ref val) => fidl::encoding::encode_in_envelope::<i32, D>(
645                    <i32 as fidl::encoding::ValueTypeMarker>::borrow(val),
646                    encoder,
647                    offset + 8,
648                    _depth,
649                ),
650            }
651        }
652    }
653
654    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Command {
655        #[inline(always)]
656        fn new_empty() -> Self {
657            Self::Empty(fidl::new_empty!(i32, D))
658        }
659
660        #[inline]
661        unsafe fn decode(
662            &mut self,
663            decoder: &mut fidl::encoding::Decoder<'_, D>,
664            offset: usize,
665            mut depth: fidl::encoding::Depth,
666        ) -> fidl::Result<()> {
667            decoder.debug_check_bounds::<Self>(offset);
668            #[allow(unused_variables)]
669            let next_out_of_line = decoder.next_out_of_line();
670            let handles_before = decoder.remaining_handles();
671            let (ordinal, inlined, num_bytes, num_handles) =
672                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
673
674            let member_inline_size = match ordinal {
675                1 => <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
676                _ => return Err(fidl::Error::UnknownUnionTag),
677            };
678
679            if inlined != (member_inline_size <= 4) {
680                return Err(fidl::Error::InvalidInlineBitInEnvelope);
681            }
682            let _inner_offset;
683            if inlined {
684                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
685                _inner_offset = offset + 8;
686            } else {
687                depth.increment()?;
688                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
689            }
690            match ordinal {
691                1 => {
692                    #[allow(irrefutable_let_patterns)]
693                    if let Command::Empty(_) = self {
694                        // Do nothing, read the value into the object
695                    } else {
696                        // Initialize `self` to the right variant
697                        *self = Command::Empty(fidl::new_empty!(i32, D));
698                    }
699                    #[allow(irrefutable_let_patterns)]
700                    if let Command::Empty(ref mut val) = self {
701                        fidl::decode!(i32, D, val, decoder, _inner_offset, depth)?;
702                    } else {
703                        unreachable!()
704                    }
705                }
706                ordinal => panic!("unexpected ordinal {:?}", ordinal),
707            }
708            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
709                return Err(fidl::Error::InvalidNumBytesInEnvelope);
710            }
711            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
712                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
713            }
714            Ok(())
715        }
716    }
717}