fidl_test_configexample/
fidl_test_configexample.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::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14pub struct ConfigUserIsManagingPowerResponse {
15    pub is_managing_power: bool,
16}
17
18impl fidl::Persistable for ConfigUserIsManagingPowerResponse {}
19
20#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
21pub struct ConfigUserMarker;
22
23impl fidl::endpoints::ProtocolMarker for ConfigUserMarker {
24    type Proxy = ConfigUserProxy;
25    type RequestStream = ConfigUserRequestStream;
26    #[cfg(target_os = "fuchsia")]
27    type SynchronousProxy = ConfigUserSynchronousProxy;
28
29    const DEBUG_NAME: &'static str = "test.configexample.ConfigUser";
30}
31impl fidl::endpoints::DiscoverableProtocolMarker for ConfigUserMarker {}
32
33pub trait ConfigUserProxyInterface: Send + Sync {
34    type IsManagingPowerResponseFut: std::future::Future<Output = Result<bool, fidl::Error>> + Send;
35    fn r#is_managing_power(&self) -> Self::IsManagingPowerResponseFut;
36}
37#[derive(Debug)]
38#[cfg(target_os = "fuchsia")]
39pub struct ConfigUserSynchronousProxy {
40    client: fidl::client::sync::Client,
41}
42
43#[cfg(target_os = "fuchsia")]
44impl fidl::endpoints::SynchronousProxy for ConfigUserSynchronousProxy {
45    type Proxy = ConfigUserProxy;
46    type Protocol = ConfigUserMarker;
47
48    fn from_channel(inner: fidl::Channel) -> Self {
49        Self::new(inner)
50    }
51
52    fn into_channel(self) -> fidl::Channel {
53        self.client.into_channel()
54    }
55
56    fn as_channel(&self) -> &fidl::Channel {
57        self.client.as_channel()
58    }
59}
60
61#[cfg(target_os = "fuchsia")]
62impl ConfigUserSynchronousProxy {
63    pub fn new(channel: fidl::Channel) -> Self {
64        let protocol_name = <ConfigUserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
65        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
66    }
67
68    pub fn into_channel(self) -> fidl::Channel {
69        self.client.into_channel()
70    }
71
72    /// Waits until an event arrives and returns it. It is safe for other
73    /// threads to make concurrent requests while waiting for an event.
74    pub fn wait_for_event(
75        &self,
76        deadline: zx::MonotonicInstant,
77    ) -> Result<ConfigUserEvent, fidl::Error> {
78        ConfigUserEvent::decode(self.client.wait_for_event(deadline)?)
79    }
80
81    pub fn r#is_managing_power(
82        &self,
83        ___deadline: zx::MonotonicInstant,
84    ) -> Result<bool, fidl::Error> {
85        let _response = self.client.send_query::<
86            fidl::encoding::EmptyPayload,
87            fidl::encoding::FlexibleType<ConfigUserIsManagingPowerResponse>,
88        >(
89            (),
90            0x3ed8a6f9f9f9fae7,
91            fidl::encoding::DynamicFlags::FLEXIBLE,
92            ___deadline,
93        )?
94        .into_result::<ConfigUserMarker>("is_managing_power")?;
95        Ok(_response.is_managing_power)
96    }
97}
98
99#[derive(Debug, Clone)]
100pub struct ConfigUserProxy {
101    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
102}
103
104impl fidl::endpoints::Proxy for ConfigUserProxy {
105    type Protocol = ConfigUserMarker;
106
107    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
108        Self::new(inner)
109    }
110
111    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
112        self.client.into_channel().map_err(|client| Self { client })
113    }
114
115    fn as_channel(&self) -> &::fidl::AsyncChannel {
116        self.client.as_channel()
117    }
118}
119
120impl ConfigUserProxy {
121    /// Create a new Proxy for test.configexample/ConfigUser.
122    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
123        let protocol_name = <ConfigUserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
124        Self { client: fidl::client::Client::new(channel, protocol_name) }
125    }
126
127    /// Get a Stream of events from the remote end of the protocol.
128    ///
129    /// # Panics
130    ///
131    /// Panics if the event stream was already taken.
132    pub fn take_event_stream(&self) -> ConfigUserEventStream {
133        ConfigUserEventStream { event_receiver: self.client.take_event_receiver() }
134    }
135
136    pub fn r#is_managing_power(
137        &self,
138    ) -> fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect> {
139        ConfigUserProxyInterface::r#is_managing_power(self)
140    }
141}
142
143impl ConfigUserProxyInterface for ConfigUserProxy {
144    type IsManagingPowerResponseFut =
145        fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect>;
146    fn r#is_managing_power(&self) -> Self::IsManagingPowerResponseFut {
147        fn _decode(
148            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
149        ) -> Result<bool, fidl::Error> {
150            let _response = fidl::client::decode_transaction_body::<
151                fidl::encoding::FlexibleType<ConfigUserIsManagingPowerResponse>,
152                fidl::encoding::DefaultFuchsiaResourceDialect,
153                0x3ed8a6f9f9f9fae7,
154            >(_buf?)?
155            .into_result::<ConfigUserMarker>("is_managing_power")?;
156            Ok(_response.is_managing_power)
157        }
158        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, bool>(
159            (),
160            0x3ed8a6f9f9f9fae7,
161            fidl::encoding::DynamicFlags::FLEXIBLE,
162            _decode,
163        )
164    }
165}
166
167pub struct ConfigUserEventStream {
168    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
169}
170
171impl std::marker::Unpin for ConfigUserEventStream {}
172
173impl futures::stream::FusedStream for ConfigUserEventStream {
174    fn is_terminated(&self) -> bool {
175        self.event_receiver.is_terminated()
176    }
177}
178
179impl futures::Stream for ConfigUserEventStream {
180    type Item = Result<ConfigUserEvent, fidl::Error>;
181
182    fn poll_next(
183        mut self: std::pin::Pin<&mut Self>,
184        cx: &mut std::task::Context<'_>,
185    ) -> std::task::Poll<Option<Self::Item>> {
186        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
187            &mut self.event_receiver,
188            cx
189        )?) {
190            Some(buf) => std::task::Poll::Ready(Some(ConfigUserEvent::decode(buf))),
191            None => std::task::Poll::Ready(None),
192        }
193    }
194}
195
196#[derive(Debug)]
197pub enum ConfigUserEvent {
198    #[non_exhaustive]
199    _UnknownEvent {
200        /// Ordinal of the event that was sent.
201        ordinal: u64,
202    },
203}
204
205impl ConfigUserEvent {
206    /// Decodes a message buffer as a [`ConfigUserEvent`].
207    fn decode(
208        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
209    ) -> Result<ConfigUserEvent, fidl::Error> {
210        let (bytes, _handles) = buf.split_mut();
211        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
212        debug_assert_eq!(tx_header.tx_id, 0);
213        match tx_header.ordinal {
214            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
215                Ok(ConfigUserEvent::_UnknownEvent { ordinal: tx_header.ordinal })
216            }
217            _ => Err(fidl::Error::UnknownOrdinal {
218                ordinal: tx_header.ordinal,
219                protocol_name: <ConfigUserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
220            }),
221        }
222    }
223}
224
225/// A Stream of incoming requests for test.configexample/ConfigUser.
226pub struct ConfigUserRequestStream {
227    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
228    is_terminated: bool,
229}
230
231impl std::marker::Unpin for ConfigUserRequestStream {}
232
233impl futures::stream::FusedStream for ConfigUserRequestStream {
234    fn is_terminated(&self) -> bool {
235        self.is_terminated
236    }
237}
238
239impl fidl::endpoints::RequestStream for ConfigUserRequestStream {
240    type Protocol = ConfigUserMarker;
241    type ControlHandle = ConfigUserControlHandle;
242
243    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
244        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
245    }
246
247    fn control_handle(&self) -> Self::ControlHandle {
248        ConfigUserControlHandle { inner: self.inner.clone() }
249    }
250
251    fn into_inner(
252        self,
253    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
254    {
255        (self.inner, self.is_terminated)
256    }
257
258    fn from_inner(
259        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
260        is_terminated: bool,
261    ) -> Self {
262        Self { inner, is_terminated }
263    }
264}
265
266impl futures::Stream for ConfigUserRequestStream {
267    type Item = Result<ConfigUserRequest, fidl::Error>;
268
269    fn poll_next(
270        mut self: std::pin::Pin<&mut Self>,
271        cx: &mut std::task::Context<'_>,
272    ) -> std::task::Poll<Option<Self::Item>> {
273        let this = &mut *self;
274        if this.inner.check_shutdown(cx) {
275            this.is_terminated = true;
276            return std::task::Poll::Ready(None);
277        }
278        if this.is_terminated {
279            panic!("polled ConfigUserRequestStream after completion");
280        }
281        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
282            |bytes, handles| {
283                match this.inner.channel().read_etc(cx, bytes, handles) {
284                    std::task::Poll::Ready(Ok(())) => {}
285                    std::task::Poll::Pending => return std::task::Poll::Pending,
286                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
287                        this.is_terminated = true;
288                        return std::task::Poll::Ready(None);
289                    }
290                    std::task::Poll::Ready(Err(e)) => {
291                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
292                            e.into(),
293                        ))))
294                    }
295                }
296
297                // A message has been received from the channel
298                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
299
300                std::task::Poll::Ready(Some(match header.ordinal {
301                    0x3ed8a6f9f9f9fae7 => {
302                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
303                        let mut req = fidl::new_empty!(
304                            fidl::encoding::EmptyPayload,
305                            fidl::encoding::DefaultFuchsiaResourceDialect
306                        );
307                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
308                        let control_handle = ConfigUserControlHandle { inner: this.inner.clone() };
309                        Ok(ConfigUserRequest::IsManagingPower {
310                            responder: ConfigUserIsManagingPowerResponder {
311                                control_handle: std::mem::ManuallyDrop::new(control_handle),
312                                tx_id: header.tx_id,
313                            },
314                        })
315                    }
316                    _ if header.tx_id == 0
317                        && header
318                            .dynamic_flags()
319                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
320                    {
321                        Ok(ConfigUserRequest::_UnknownMethod {
322                            ordinal: header.ordinal,
323                            control_handle: ConfigUserControlHandle { inner: this.inner.clone() },
324                            method_type: fidl::MethodType::OneWay,
325                        })
326                    }
327                    _ if header
328                        .dynamic_flags()
329                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
330                    {
331                        this.inner.send_framework_err(
332                            fidl::encoding::FrameworkErr::UnknownMethod,
333                            header.tx_id,
334                            header.ordinal,
335                            header.dynamic_flags(),
336                            (bytes, handles),
337                        )?;
338                        Ok(ConfigUserRequest::_UnknownMethod {
339                            ordinal: header.ordinal,
340                            control_handle: ConfigUserControlHandle { inner: this.inner.clone() },
341                            method_type: fidl::MethodType::TwoWay,
342                        })
343                    }
344                    _ => Err(fidl::Error::UnknownOrdinal {
345                        ordinal: header.ordinal,
346                        protocol_name:
347                            <ConfigUserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
348                    }),
349                }))
350            },
351        )
352    }
353}
354
355/// This protocol allows the config client to report whether it is managing power. This provides a
356/// minimal way for the client to demonstrate a behavior change that is observable to the test
357/// component. A real client's interactions with the external system will likely change in ways that
358/// are considerably more complex.
359#[derive(Debug)]
360pub enum ConfigUserRequest {
361    IsManagingPower {
362        responder: ConfigUserIsManagingPowerResponder,
363    },
364    /// An interaction was received which does not match any known method.
365    #[non_exhaustive]
366    _UnknownMethod {
367        /// Ordinal of the method that was called.
368        ordinal: u64,
369        control_handle: ConfigUserControlHandle,
370        method_type: fidl::MethodType,
371    },
372}
373
374impl ConfigUserRequest {
375    #[allow(irrefutable_let_patterns)]
376    pub fn into_is_managing_power(self) -> Option<(ConfigUserIsManagingPowerResponder)> {
377        if let ConfigUserRequest::IsManagingPower { responder } = self {
378            Some((responder))
379        } else {
380            None
381        }
382    }
383
384    /// Name of the method defined in FIDL
385    pub fn method_name(&self) -> &'static str {
386        match *self {
387            ConfigUserRequest::IsManagingPower { .. } => "is_managing_power",
388            ConfigUserRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
389                "unknown one-way method"
390            }
391            ConfigUserRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
392                "unknown two-way method"
393            }
394        }
395    }
396}
397
398#[derive(Debug, Clone)]
399pub struct ConfigUserControlHandle {
400    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
401}
402
403impl fidl::endpoints::ControlHandle for ConfigUserControlHandle {
404    fn shutdown(&self) {
405        self.inner.shutdown()
406    }
407    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
408        self.inner.shutdown_with_epitaph(status)
409    }
410
411    fn is_closed(&self) -> bool {
412        self.inner.channel().is_closed()
413    }
414    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
415        self.inner.channel().on_closed()
416    }
417
418    #[cfg(target_os = "fuchsia")]
419    fn signal_peer(
420        &self,
421        clear_mask: zx::Signals,
422        set_mask: zx::Signals,
423    ) -> Result<(), zx_status::Status> {
424        use fidl::Peered;
425        self.inner.channel().signal_peer(clear_mask, set_mask)
426    }
427}
428
429impl ConfigUserControlHandle {}
430
431#[must_use = "FIDL methods require a response to be sent"]
432#[derive(Debug)]
433pub struct ConfigUserIsManagingPowerResponder {
434    control_handle: std::mem::ManuallyDrop<ConfigUserControlHandle>,
435    tx_id: u32,
436}
437
438/// Set the the channel to be shutdown (see [`ConfigUserControlHandle::shutdown`])
439/// if the responder is dropped without sending a response, so that the client
440/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
441impl std::ops::Drop for ConfigUserIsManagingPowerResponder {
442    fn drop(&mut self) {
443        self.control_handle.shutdown();
444        // Safety: drops once, never accessed again
445        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
446    }
447}
448
449impl fidl::endpoints::Responder for ConfigUserIsManagingPowerResponder {
450    type ControlHandle = ConfigUserControlHandle;
451
452    fn control_handle(&self) -> &ConfigUserControlHandle {
453        &self.control_handle
454    }
455
456    fn drop_without_shutdown(mut self) {
457        // Safety: drops once, never accessed again due to mem::forget
458        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
459        // Prevent Drop from running (which would shut down the channel)
460        std::mem::forget(self);
461    }
462}
463
464impl ConfigUserIsManagingPowerResponder {
465    /// Sends a response to the FIDL transaction.
466    ///
467    /// Sets the channel to shutdown if an error occurs.
468    pub fn send(self, mut is_managing_power: bool) -> Result<(), fidl::Error> {
469        let _result = self.send_raw(is_managing_power);
470        if _result.is_err() {
471            self.control_handle.shutdown();
472        }
473        self.drop_without_shutdown();
474        _result
475    }
476
477    /// Similar to "send" but does not shutdown the channel if an error occurs.
478    pub fn send_no_shutdown_on_err(self, mut is_managing_power: bool) -> Result<(), fidl::Error> {
479        let _result = self.send_raw(is_managing_power);
480        self.drop_without_shutdown();
481        _result
482    }
483
484    fn send_raw(&self, mut is_managing_power: bool) -> Result<(), fidl::Error> {
485        self.control_handle
486            .inner
487            .send::<fidl::encoding::FlexibleType<ConfigUserIsManagingPowerResponse>>(
488                fidl::encoding::Flexible::new((is_managing_power,)),
489                self.tx_id,
490                0x3ed8a6f9f9f9fae7,
491                fidl::encoding::DynamicFlags::FLEXIBLE,
492            )
493    }
494}
495
496mod internal {
497    use super::*;
498
499    impl fidl::encoding::ValueTypeMarker for ConfigUserIsManagingPowerResponse {
500        type Borrowed<'a> = &'a Self;
501        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
502            value
503        }
504    }
505
506    unsafe impl fidl::encoding::TypeMarker for ConfigUserIsManagingPowerResponse {
507        type Owned = Self;
508
509        #[inline(always)]
510        fn inline_align(_context: fidl::encoding::Context) -> usize {
511            1
512        }
513
514        #[inline(always)]
515        fn inline_size(_context: fidl::encoding::Context) -> usize {
516            1
517        }
518    }
519
520    unsafe impl<D: fidl::encoding::ResourceDialect>
521        fidl::encoding::Encode<ConfigUserIsManagingPowerResponse, D>
522        for &ConfigUserIsManagingPowerResponse
523    {
524        #[inline]
525        unsafe fn encode(
526            self,
527            encoder: &mut fidl::encoding::Encoder<'_, D>,
528            offset: usize,
529            _depth: fidl::encoding::Depth,
530        ) -> fidl::Result<()> {
531            encoder.debug_check_bounds::<ConfigUserIsManagingPowerResponse>(offset);
532            // Delegate to tuple encoding.
533            fidl::encoding::Encode::<ConfigUserIsManagingPowerResponse, D>::encode(
534                (<bool as fidl::encoding::ValueTypeMarker>::borrow(&self.is_managing_power),),
535                encoder,
536                offset,
537                _depth,
538            )
539        }
540    }
541    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<bool, D>>
542        fidl::encoding::Encode<ConfigUserIsManagingPowerResponse, D> for (T0,)
543    {
544        #[inline]
545        unsafe fn encode(
546            self,
547            encoder: &mut fidl::encoding::Encoder<'_, D>,
548            offset: usize,
549            depth: fidl::encoding::Depth,
550        ) -> fidl::Result<()> {
551            encoder.debug_check_bounds::<ConfigUserIsManagingPowerResponse>(offset);
552            // Zero out padding regions. There's no need to apply masks
553            // because the unmasked parts will be overwritten by fields.
554            // Write the fields.
555            self.0.encode(encoder, offset + 0, depth)?;
556            Ok(())
557        }
558    }
559
560    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
561        for ConfigUserIsManagingPowerResponse
562    {
563        #[inline(always)]
564        fn new_empty() -> Self {
565            Self { is_managing_power: fidl::new_empty!(bool, D) }
566        }
567
568        #[inline]
569        unsafe fn decode(
570            &mut self,
571            decoder: &mut fidl::encoding::Decoder<'_, D>,
572            offset: usize,
573            _depth: fidl::encoding::Depth,
574        ) -> fidl::Result<()> {
575            decoder.debug_check_bounds::<Self>(offset);
576            // Verify that padding bytes are zero.
577            fidl::decode!(bool, D, &mut self.is_managing_power, decoder, offset + 0, _depth)?;
578            Ok(())
579        }
580    }
581}