fidl_fuchsia_component_resolution__common/
fidl_fuchsia_component_resolution__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/// Max length of component URL.
12pub const MAX_COMPONENT_URL_LENGTH: u32 = 2083;
13
14/// The maximum number of bytes for a `Context`.
15pub const MAX_RESOLUTION_CONTEXT_SIZE: u32 = 8192;
16
17/// The possible error conditions returned by ComponentResolver.
18#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
19#[repr(u32)]
20pub enum ResolverError {
21    /// An unexpected error occurred.
22    Internal = 1,
23    /// A general IO error occurred.
24    Io = 2,
25    /// The component URL was malformed.
26    InvalidArgs = 3,
27    /// The repository specified in the URL is unsupported.
28    NotSupported = 4,
29    /// The component manifest was not found.
30    ManifestNotFound = 5,
31    /// The component's package was not found.
32    PackageNotFound = 6,
33    /// Insufficient space on device to store component's package.
34    NoSpace = 7,
35    /// The component is temporarily unavailable.
36    ResourceUnavailable = 8,
37    /// The component manifest could not be parsed or it contained invalid configuration.
38    InvalidManifest = 9,
39    /// The component specifies configuration fields but the values were not found.
40    ConfigValuesNotFound = 10,
41    /// The ABI revision file could not be found.
42    AbiRevisionNotFound = 11,
43    /// The ABI revision value could not be parsed.
44    InvalidAbiRevision = 12,
45}
46
47impl ResolverError {
48    #[inline]
49    pub fn from_primitive(prim: u32) -> Option<Self> {
50        match prim {
51            1 => Some(Self::Internal),
52            2 => Some(Self::Io),
53            3 => Some(Self::InvalidArgs),
54            4 => Some(Self::NotSupported),
55            5 => Some(Self::ManifestNotFound),
56            6 => Some(Self::PackageNotFound),
57            7 => Some(Self::NoSpace),
58            8 => Some(Self::ResourceUnavailable),
59            9 => Some(Self::InvalidManifest),
60            10 => Some(Self::ConfigValuesNotFound),
61            11 => Some(Self::AbiRevisionNotFound),
62            12 => Some(Self::InvalidAbiRevision),
63            _ => None,
64        }
65    }
66
67    #[inline]
68    pub const fn into_primitive(self) -> u32 {
69        self as u32
70    }
71}
72
73/// A component resolution context, used when resolving component URLs relative
74/// to another component. The context is stored in a byte array that persists a
75/// value used by the target `Resolver` to locate and resolve a component by
76/// relative path (for example, by a subpackage name).
77#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
78pub struct Context {
79    pub bytes: Vec<u8>,
80}
81
82impl fidl::Persistable for Context {}
83
84#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
85pub struct ResolverResolveRequest {
86    pub component_url: String,
87}
88
89impl fidl::Persistable for ResolverResolveRequest {}
90
91#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
92pub struct ResolverResolveWithContextRequest {
93    pub component_url: String,
94    pub context: Context,
95}
96
97impl fidl::Persistable for ResolverResolveWithContextRequest {}
98
99mod internal {
100    use super::*;
101    unsafe impl fidl::encoding::TypeMarker for ResolverError {
102        type Owned = Self;
103
104        #[inline(always)]
105        fn inline_align(_context: fidl::encoding::Context) -> usize {
106            std::mem::align_of::<u32>()
107        }
108
109        #[inline(always)]
110        fn inline_size(_context: fidl::encoding::Context) -> usize {
111            std::mem::size_of::<u32>()
112        }
113
114        #[inline(always)]
115        fn encode_is_copy() -> bool {
116            true
117        }
118
119        #[inline(always)]
120        fn decode_is_copy() -> bool {
121            false
122        }
123    }
124
125    impl fidl::encoding::ValueTypeMarker for ResolverError {
126        type Borrowed<'a> = Self;
127        #[inline(always)]
128        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
129            *value
130        }
131    }
132
133    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for ResolverError {
134        #[inline]
135        unsafe fn encode(
136            self,
137            encoder: &mut fidl::encoding::Encoder<'_, D>,
138            offset: usize,
139            _depth: fidl::encoding::Depth,
140        ) -> fidl::Result<()> {
141            encoder.debug_check_bounds::<Self>(offset);
142            encoder.write_num(self.into_primitive(), offset);
143            Ok(())
144        }
145    }
146
147    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ResolverError {
148        #[inline(always)]
149        fn new_empty() -> Self {
150            Self::Internal
151        }
152
153        #[inline]
154        unsafe fn decode(
155            &mut self,
156            decoder: &mut fidl::encoding::Decoder<'_, D>,
157            offset: usize,
158            _depth: fidl::encoding::Depth,
159        ) -> fidl::Result<()> {
160            decoder.debug_check_bounds::<Self>(offset);
161            let prim = decoder.read_num::<u32>(offset);
162
163            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
164            Ok(())
165        }
166    }
167
168    impl fidl::encoding::ValueTypeMarker for Context {
169        type Borrowed<'a> = &'a Self;
170        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
171            value
172        }
173    }
174
175    unsafe impl fidl::encoding::TypeMarker for Context {
176        type Owned = Self;
177
178        #[inline(always)]
179        fn inline_align(_context: fidl::encoding::Context) -> usize {
180            8
181        }
182
183        #[inline(always)]
184        fn inline_size(_context: fidl::encoding::Context) -> usize {
185            16
186        }
187    }
188
189    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Context, D> for &Context {
190        #[inline]
191        unsafe fn encode(
192            self,
193            encoder: &mut fidl::encoding::Encoder<'_, D>,
194            offset: usize,
195            _depth: fidl::encoding::Depth,
196        ) -> fidl::Result<()> {
197            encoder.debug_check_bounds::<Context>(offset);
198            // Delegate to tuple encoding.
199            fidl::encoding::Encode::<Context, D>::encode(
200                (<fidl::encoding::Vector<u8, 8192> as fidl::encoding::ValueTypeMarker>::borrow(
201                    &self.bytes,
202                ),),
203                encoder,
204                offset,
205                _depth,
206            )
207        }
208    }
209    unsafe impl<
210            D: fidl::encoding::ResourceDialect,
211            T0: fidl::encoding::Encode<fidl::encoding::Vector<u8, 8192>, D>,
212        > fidl::encoding::Encode<Context, D> for (T0,)
213    {
214        #[inline]
215        unsafe fn encode(
216            self,
217            encoder: &mut fidl::encoding::Encoder<'_, D>,
218            offset: usize,
219            depth: fidl::encoding::Depth,
220        ) -> fidl::Result<()> {
221            encoder.debug_check_bounds::<Context>(offset);
222            // Zero out padding regions. There's no need to apply masks
223            // because the unmasked parts will be overwritten by fields.
224            // Write the fields.
225            self.0.encode(encoder, offset + 0, depth)?;
226            Ok(())
227        }
228    }
229
230    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Context {
231        #[inline(always)]
232        fn new_empty() -> Self {
233            Self { bytes: fidl::new_empty!(fidl::encoding::Vector<u8, 8192>, D) }
234        }
235
236        #[inline]
237        unsafe fn decode(
238            &mut self,
239            decoder: &mut fidl::encoding::Decoder<'_, D>,
240            offset: usize,
241            _depth: fidl::encoding::Depth,
242        ) -> fidl::Result<()> {
243            decoder.debug_check_bounds::<Self>(offset);
244            // Verify that padding bytes are zero.
245            fidl::decode!(fidl::encoding::Vector<u8, 8192>, D, &mut self.bytes, decoder, offset + 0, _depth)?;
246            Ok(())
247        }
248    }
249
250    impl fidl::encoding::ValueTypeMarker for ResolverResolveRequest {
251        type Borrowed<'a> = &'a Self;
252        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
253            value
254        }
255    }
256
257    unsafe impl fidl::encoding::TypeMarker for ResolverResolveRequest {
258        type Owned = Self;
259
260        #[inline(always)]
261        fn inline_align(_context: fidl::encoding::Context) -> usize {
262            8
263        }
264
265        #[inline(always)]
266        fn inline_size(_context: fidl::encoding::Context) -> usize {
267            16
268        }
269    }
270
271    unsafe impl<D: fidl::encoding::ResourceDialect>
272        fidl::encoding::Encode<ResolverResolveRequest, D> for &ResolverResolveRequest
273    {
274        #[inline]
275        unsafe fn encode(
276            self,
277            encoder: &mut fidl::encoding::Encoder<'_, D>,
278            offset: usize,
279            _depth: fidl::encoding::Depth,
280        ) -> fidl::Result<()> {
281            encoder.debug_check_bounds::<ResolverResolveRequest>(offset);
282            // Delegate to tuple encoding.
283            fidl::encoding::Encode::<ResolverResolveRequest, D>::encode(
284                (<fidl::encoding::BoundedString<2083> as fidl::encoding::ValueTypeMarker>::borrow(
285                    &self.component_url,
286                ),),
287                encoder,
288                offset,
289                _depth,
290            )
291        }
292    }
293    unsafe impl<
294            D: fidl::encoding::ResourceDialect,
295            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<2083>, D>,
296        > fidl::encoding::Encode<ResolverResolveRequest, D> for (T0,)
297    {
298        #[inline]
299        unsafe fn encode(
300            self,
301            encoder: &mut fidl::encoding::Encoder<'_, D>,
302            offset: usize,
303            depth: fidl::encoding::Depth,
304        ) -> fidl::Result<()> {
305            encoder.debug_check_bounds::<ResolverResolveRequest>(offset);
306            // Zero out padding regions. There's no need to apply masks
307            // because the unmasked parts will be overwritten by fields.
308            // Write the fields.
309            self.0.encode(encoder, offset + 0, depth)?;
310            Ok(())
311        }
312    }
313
314    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
315        for ResolverResolveRequest
316    {
317        #[inline(always)]
318        fn new_empty() -> Self {
319            Self { component_url: fidl::new_empty!(fidl::encoding::BoundedString<2083>, 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            // Verify that padding bytes are zero.
331            fidl::decode!(
332                fidl::encoding::BoundedString<2083>,
333                D,
334                &mut self.component_url,
335                decoder,
336                offset + 0,
337                _depth
338            )?;
339            Ok(())
340        }
341    }
342
343    impl fidl::encoding::ValueTypeMarker for ResolverResolveWithContextRequest {
344        type Borrowed<'a> = &'a Self;
345        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
346            value
347        }
348    }
349
350    unsafe impl fidl::encoding::TypeMarker for ResolverResolveWithContextRequest {
351        type Owned = Self;
352
353        #[inline(always)]
354        fn inline_align(_context: fidl::encoding::Context) -> usize {
355            8
356        }
357
358        #[inline(always)]
359        fn inline_size(_context: fidl::encoding::Context) -> usize {
360            32
361        }
362    }
363
364    unsafe impl<D: fidl::encoding::ResourceDialect>
365        fidl::encoding::Encode<ResolverResolveWithContextRequest, D>
366        for &ResolverResolveWithContextRequest
367    {
368        #[inline]
369        unsafe fn encode(
370            self,
371            encoder: &mut fidl::encoding::Encoder<'_, D>,
372            offset: usize,
373            _depth: fidl::encoding::Depth,
374        ) -> fidl::Result<()> {
375            encoder.debug_check_bounds::<ResolverResolveWithContextRequest>(offset);
376            // Delegate to tuple encoding.
377            fidl::encoding::Encode::<ResolverResolveWithContextRequest, D>::encode(
378                (
379                    <fidl::encoding::BoundedString<2083> as fidl::encoding::ValueTypeMarker>::borrow(&self.component_url),
380                    <Context as fidl::encoding::ValueTypeMarker>::borrow(&self.context),
381                ),
382                encoder, offset, _depth
383            )
384        }
385    }
386    unsafe impl<
387            D: fidl::encoding::ResourceDialect,
388            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<2083>, D>,
389            T1: fidl::encoding::Encode<Context, D>,
390        > fidl::encoding::Encode<ResolverResolveWithContextRequest, D> for (T0, T1)
391    {
392        #[inline]
393        unsafe fn encode(
394            self,
395            encoder: &mut fidl::encoding::Encoder<'_, D>,
396            offset: usize,
397            depth: fidl::encoding::Depth,
398        ) -> fidl::Result<()> {
399            encoder.debug_check_bounds::<ResolverResolveWithContextRequest>(offset);
400            // Zero out padding regions. There's no need to apply masks
401            // because the unmasked parts will be overwritten by fields.
402            // Write the fields.
403            self.0.encode(encoder, offset + 0, depth)?;
404            self.1.encode(encoder, offset + 16, depth)?;
405            Ok(())
406        }
407    }
408
409    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
410        for ResolverResolveWithContextRequest
411    {
412        #[inline(always)]
413        fn new_empty() -> Self {
414            Self {
415                component_url: fidl::new_empty!(fidl::encoding::BoundedString<2083>, D),
416                context: fidl::new_empty!(Context, D),
417            }
418        }
419
420        #[inline]
421        unsafe fn decode(
422            &mut self,
423            decoder: &mut fidl::encoding::Decoder<'_, D>,
424            offset: usize,
425            _depth: fidl::encoding::Depth,
426        ) -> fidl::Result<()> {
427            decoder.debug_check_bounds::<Self>(offset);
428            // Verify that padding bytes are zero.
429            fidl::decode!(
430                fidl::encoding::BoundedString<2083>,
431                D,
432                &mut self.component_url,
433                decoder,
434                offset + 0,
435                _depth
436            )?;
437            fidl::decode!(Context, D, &mut self.context, decoder, offset + 16, _depth)?;
438            Ok(())
439        }
440    }
441}