Skip to main content

fidl_fuchsia_testing_simple/
fidl_fuchsia_testing_simple.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 _};
10pub use fidl_fuchsia_testing_simple__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct SimpleMarker;
16
17impl fidl::endpoints::ProtocolMarker for SimpleMarker {
18    type Proxy = SimpleProxy;
19    type RequestStream = SimpleRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = SimpleSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.testing.simple.Simple";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for SimpleMarker {}
26pub type SimpleOnStartResult = Result<(), i32>;
27
28pub trait SimpleProxyInterface: Send + Sync {
29    type OnStartResponseFut: std::future::Future<Output = Result<SimpleOnStartResult, fidl::Error>>
30        + Send;
31    fn r#on_start(&self) -> Self::OnStartResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct SimpleSynchronousProxy {
36    client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for SimpleSynchronousProxy {
41    type Proxy = SimpleProxy;
42    type Protocol = SimpleMarker;
43
44    fn from_channel(inner: fidl::Channel) -> Self {
45        Self::new(inner)
46    }
47
48    fn into_channel(self) -> fidl::Channel {
49        self.client.into_channel()
50    }
51
52    fn as_channel(&self) -> &fidl::Channel {
53        self.client.as_channel()
54    }
55}
56
57#[cfg(target_os = "fuchsia")]
58impl SimpleSynchronousProxy {
59    pub fn new(channel: fidl::Channel) -> Self {
60        let protocol_name = <SimpleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
61        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
62    }
63
64    pub fn into_channel(self) -> fidl::Channel {
65        self.client.into_channel()
66    }
67
68    /// Waits until an event arrives and returns it. It is safe for other
69    /// threads to make concurrent requests while waiting for an event.
70    pub fn wait_for_event(
71        &self,
72        deadline: zx::MonotonicInstant,
73    ) -> Result<SimpleEvent, fidl::Error> {
74        SimpleEvent::decode(self.client.wait_for_event(deadline)?)
75    }
76
77    pub fn r#on_start(
78        &self,
79        ___deadline: zx::MonotonicInstant,
80    ) -> Result<SimpleOnStartResult, fidl::Error> {
81        let _response = self.client.send_query::<
82            fidl::encoding::EmptyPayload,
83            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
84        >(
85            (),
86            0x612217451a360794,
87            fidl::encoding::DynamicFlags::empty(),
88            ___deadline,
89        )?;
90        Ok(_response.map(|x| x))
91    }
92}
93
94#[cfg(target_os = "fuchsia")]
95impl From<SimpleSynchronousProxy> for zx::NullableHandle {
96    fn from(value: SimpleSynchronousProxy) -> Self {
97        value.into_channel().into()
98    }
99}
100
101#[cfg(target_os = "fuchsia")]
102impl From<fidl::Channel> for SimpleSynchronousProxy {
103    fn from(value: fidl::Channel) -> Self {
104        Self::new(value)
105    }
106}
107
108#[cfg(target_os = "fuchsia")]
109impl fidl::endpoints::FromClient for SimpleSynchronousProxy {
110    type Protocol = SimpleMarker;
111
112    fn from_client(value: fidl::endpoints::ClientEnd<SimpleMarker>) -> Self {
113        Self::new(value.into_channel())
114    }
115}
116
117#[derive(Debug, Clone)]
118pub struct SimpleProxy {
119    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
120}
121
122impl fidl::endpoints::Proxy for SimpleProxy {
123    type Protocol = SimpleMarker;
124
125    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
126        Self::new(inner)
127    }
128
129    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
130        self.client.into_channel().map_err(|client| Self { client })
131    }
132
133    fn as_channel(&self) -> &::fidl::AsyncChannel {
134        self.client.as_channel()
135    }
136}
137
138impl SimpleProxy {
139    /// Create a new Proxy for fuchsia.testing.simple/Simple.
140    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
141        let protocol_name = <SimpleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
142        Self { client: fidl::client::Client::new(channel, protocol_name) }
143    }
144
145    /// Get a Stream of events from the remote end of the protocol.
146    ///
147    /// # Panics
148    ///
149    /// Panics if the event stream was already taken.
150    pub fn take_event_stream(&self) -> SimpleEventStream {
151        SimpleEventStream { event_receiver: self.client.take_event_receiver() }
152    }
153
154    pub fn r#on_start(
155        &self,
156    ) -> fidl::client::QueryResponseFut<
157        SimpleOnStartResult,
158        fidl::encoding::DefaultFuchsiaResourceDialect,
159    > {
160        SimpleProxyInterface::r#on_start(self)
161    }
162}
163
164impl SimpleProxyInterface for SimpleProxy {
165    type OnStartResponseFut = fidl::client::QueryResponseFut<
166        SimpleOnStartResult,
167        fidl::encoding::DefaultFuchsiaResourceDialect,
168    >;
169    fn r#on_start(&self) -> Self::OnStartResponseFut {
170        fn _decode(
171            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
172        ) -> Result<SimpleOnStartResult, fidl::Error> {
173            let _response = fidl::client::decode_transaction_body::<
174                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
175                fidl::encoding::DefaultFuchsiaResourceDialect,
176                0x612217451a360794,
177            >(_buf?)?;
178            Ok(_response.map(|x| x))
179        }
180        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, SimpleOnStartResult>(
181            (),
182            0x612217451a360794,
183            fidl::encoding::DynamicFlags::empty(),
184            _decode,
185        )
186    }
187}
188
189pub struct SimpleEventStream {
190    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
191}
192
193impl std::marker::Unpin for SimpleEventStream {}
194
195impl futures::stream::FusedStream for SimpleEventStream {
196    fn is_terminated(&self) -> bool {
197        self.event_receiver.is_terminated()
198    }
199}
200
201impl futures::Stream for SimpleEventStream {
202    type Item = Result<SimpleEvent, fidl::Error>;
203
204    fn poll_next(
205        mut self: std::pin::Pin<&mut Self>,
206        cx: &mut std::task::Context<'_>,
207    ) -> std::task::Poll<Option<Self::Item>> {
208        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
209            &mut self.event_receiver,
210            cx
211        )?) {
212            Some(buf) => std::task::Poll::Ready(Some(SimpleEvent::decode(buf))),
213            None => std::task::Poll::Ready(None),
214        }
215    }
216}
217
218#[derive(Debug)]
219pub enum SimpleEvent {}
220
221impl SimpleEvent {
222    /// Decodes a message buffer as a [`SimpleEvent`].
223    fn decode(
224        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
225    ) -> Result<SimpleEvent, fidl::Error> {
226        let (bytes, _handles) = buf.split_mut();
227        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
228        debug_assert_eq!(tx_header.tx_id, 0);
229        match tx_header.ordinal {
230            _ => Err(fidl::Error::UnknownOrdinal {
231                ordinal: tx_header.ordinal,
232                protocol_name: <SimpleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
233            }),
234        }
235    }
236}
237
238/// A Stream of incoming requests for fuchsia.testing.simple/Simple.
239pub struct SimpleRequestStream {
240    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
241    is_terminated: bool,
242}
243
244impl std::marker::Unpin for SimpleRequestStream {}
245
246impl futures::stream::FusedStream for SimpleRequestStream {
247    fn is_terminated(&self) -> bool {
248        self.is_terminated
249    }
250}
251
252impl fidl::endpoints::RequestStream for SimpleRequestStream {
253    type Protocol = SimpleMarker;
254    type ControlHandle = SimpleControlHandle;
255
256    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
257        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
258    }
259
260    fn control_handle(&self) -> Self::ControlHandle {
261        SimpleControlHandle { inner: self.inner.clone() }
262    }
263
264    fn into_inner(
265        self,
266    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
267    {
268        (self.inner, self.is_terminated)
269    }
270
271    fn from_inner(
272        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
273        is_terminated: bool,
274    ) -> Self {
275        Self { inner, is_terminated }
276    }
277}
278
279impl futures::Stream for SimpleRequestStream {
280    type Item = Result<SimpleRequest, fidl::Error>;
281
282    fn poll_next(
283        mut self: std::pin::Pin<&mut Self>,
284        cx: &mut std::task::Context<'_>,
285    ) -> std::task::Poll<Option<Self::Item>> {
286        let this = &mut *self;
287        if this.inner.check_shutdown(cx) {
288            this.is_terminated = true;
289            return std::task::Poll::Ready(None);
290        }
291        if this.is_terminated {
292            panic!("polled SimpleRequestStream after completion");
293        }
294        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
295            |bytes, handles| {
296                match this.inner.channel().read_etc(cx, bytes, handles) {
297                    std::task::Poll::Ready(Ok(())) => {}
298                    std::task::Poll::Pending => return std::task::Poll::Pending,
299                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
300                        this.is_terminated = true;
301                        return std::task::Poll::Ready(None);
302                    }
303                    std::task::Poll::Ready(Err(e)) => {
304                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
305                            e.into(),
306                        ))));
307                    }
308                }
309
310                // A message has been received from the channel
311                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
312
313                std::task::Poll::Ready(Some(match header.ordinal {
314                    0x612217451a360794 => {
315                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
316                        let mut req = fidl::new_empty!(
317                            fidl::encoding::EmptyPayload,
318                            fidl::encoding::DefaultFuchsiaResourceDialect
319                        );
320                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
321                        let control_handle = SimpleControlHandle { inner: this.inner.clone() };
322                        Ok(SimpleRequest::OnStart {
323                            responder: SimpleOnStartResponder {
324                                control_handle: std::mem::ManuallyDrop::new(control_handle),
325                                tx_id: header.tx_id,
326                            },
327                        })
328                    }
329                    _ => Err(fidl::Error::UnknownOrdinal {
330                        ordinal: header.ordinal,
331                        protocol_name:
332                            <SimpleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
333                    }),
334                }))
335            },
336        )
337    }
338}
339
340#[derive(Debug)]
341pub enum SimpleRequest {
342    OnStart { responder: SimpleOnStartResponder },
343}
344
345impl SimpleRequest {
346    #[allow(irrefutable_let_patterns)]
347    pub fn into_on_start(self) -> Option<(SimpleOnStartResponder)> {
348        if let SimpleRequest::OnStart { responder } = self { Some((responder)) } else { None }
349    }
350
351    /// Name of the method defined in FIDL
352    pub fn method_name(&self) -> &'static str {
353        match *self {
354            SimpleRequest::OnStart { .. } => "on_start",
355        }
356    }
357}
358
359#[derive(Debug, Clone)]
360pub struct SimpleControlHandle {
361    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
362}
363
364impl fidl::endpoints::ControlHandle for SimpleControlHandle {
365    fn shutdown(&self) {
366        self.inner.shutdown()
367    }
368
369    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
370        self.inner.shutdown_with_epitaph(status)
371    }
372
373    fn is_closed(&self) -> bool {
374        self.inner.channel().is_closed()
375    }
376    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
377        self.inner.channel().on_closed()
378    }
379
380    #[cfg(target_os = "fuchsia")]
381    fn signal_peer(
382        &self,
383        clear_mask: zx::Signals,
384        set_mask: zx::Signals,
385    ) -> Result<(), zx_status::Status> {
386        use fidl::Peered;
387        self.inner.channel().signal_peer(clear_mask, set_mask)
388    }
389}
390
391impl SimpleControlHandle {}
392
393#[must_use = "FIDL methods require a response to be sent"]
394#[derive(Debug)]
395pub struct SimpleOnStartResponder {
396    control_handle: std::mem::ManuallyDrop<SimpleControlHandle>,
397    tx_id: u32,
398}
399
400/// Set the the channel to be shutdown (see [`SimpleControlHandle::shutdown`])
401/// if the responder is dropped without sending a response, so that the client
402/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
403impl std::ops::Drop for SimpleOnStartResponder {
404    fn drop(&mut self) {
405        self.control_handle.shutdown();
406        // Safety: drops once, never accessed again
407        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
408    }
409}
410
411impl fidl::endpoints::Responder for SimpleOnStartResponder {
412    type ControlHandle = SimpleControlHandle;
413
414    fn control_handle(&self) -> &SimpleControlHandle {
415        &self.control_handle
416    }
417
418    fn drop_without_shutdown(mut self) {
419        // Safety: drops once, never accessed again due to mem::forget
420        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
421        // Prevent Drop from running (which would shut down the channel)
422        std::mem::forget(self);
423    }
424}
425
426impl SimpleOnStartResponder {
427    /// Sends a response to the FIDL transaction.
428    ///
429    /// Sets the channel to shutdown if an error occurs.
430    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
431        let _result = self.send_raw(result);
432        if _result.is_err() {
433            self.control_handle.shutdown();
434        }
435        self.drop_without_shutdown();
436        _result
437    }
438
439    /// Similar to "send" but does not shutdown the channel if an error occurs.
440    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
441        let _result = self.send_raw(result);
442        self.drop_without_shutdown();
443        _result
444    }
445
446    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
447        self.control_handle
448            .inner
449            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
450                result,
451                self.tx_id,
452                0x612217451a360794,
453                fidl::encoding::DynamicFlags::empty(),
454            )
455    }
456}
457
458#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
459pub struct ServiceMarker;
460
461#[cfg(target_os = "fuchsia")]
462impl fidl::endpoints::ServiceMarker for ServiceMarker {
463    type Proxy = ServiceProxy;
464    type Request = ServiceRequest;
465    const SERVICE_NAME: &'static str = "fuchsia.testing.simple.Service";
466}
467
468/// A request for one of the member protocols of Service.
469///
470#[cfg(target_os = "fuchsia")]
471pub enum ServiceRequest {
472    Simple(SimpleRequestStream),
473}
474
475#[cfg(target_os = "fuchsia")]
476impl fidl::endpoints::ServiceRequest for ServiceRequest {
477    type Service = ServiceMarker;
478
479    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
480        match name {
481            "simple" => Self::Simple(
482                <SimpleRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
483            ),
484            _ => panic!("no such member protocol name for service Service"),
485        }
486    }
487
488    fn member_names() -> &'static [&'static str] {
489        &["simple"]
490    }
491}
492#[cfg(target_os = "fuchsia")]
493pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
494
495#[cfg(target_os = "fuchsia")]
496impl fidl::endpoints::ServiceProxy for ServiceProxy {
497    type Service = ServiceMarker;
498
499    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
500        Self(opener)
501    }
502}
503
504#[cfg(target_os = "fuchsia")]
505impl ServiceProxy {
506    pub fn connect_to_simple(&self) -> Result<SimpleProxy, fidl::Error> {
507        let (proxy, server_end) = fidl::endpoints::create_proxy::<SimpleMarker>();
508        self.connect_channel_to_simple(server_end)?;
509        Ok(proxy)
510    }
511
512    /// Like `connect_to_simple`, but returns a sync proxy.
513    /// See [`Self::connect_to_simple`] for more details.
514    pub fn connect_to_simple_sync(&self) -> Result<SimpleSynchronousProxy, fidl::Error> {
515        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<SimpleMarker>();
516        self.connect_channel_to_simple(server_end)?;
517        Ok(proxy)
518    }
519
520    /// Like `connect_to_simple`, but accepts a server end.
521    /// See [`Self::connect_to_simple`] for more details.
522    pub fn connect_channel_to_simple(
523        &self,
524        server_end: fidl::endpoints::ServerEnd<SimpleMarker>,
525    ) -> Result<(), fidl::Error> {
526        self.0.open_member("simple", server_end.into_channel())
527    }
528
529    pub fn instance_name(&self) -> &str {
530        self.0.instance_name()
531    }
532}
533
534mod internal {
535    use super::*;
536}