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