fidl_fuchsia_compat_runtime/
fidl_fuchsia_compat_runtime.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_compat_runtime__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct LeafMarker;
16
17impl fidl::endpoints::ProtocolMarker for LeafMarker {
18    type Proxy = LeafProxy;
19    type RequestStream = LeafRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = LeafSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "(anonymous) Leaf";
24}
25
26pub trait LeafProxyInterface: Send + Sync {
27    type GetStringResponseFut: std::future::Future<Output = Result<String, fidl::Error>> + Send;
28    fn r#get_string(&self) -> Self::GetStringResponseFut;
29}
30#[derive(Debug)]
31#[cfg(target_os = "fuchsia")]
32pub struct LeafSynchronousProxy {
33    client: fidl::client::sync::Client,
34}
35
36#[cfg(target_os = "fuchsia")]
37impl fidl::endpoints::SynchronousProxy for LeafSynchronousProxy {
38    type Proxy = LeafProxy;
39    type Protocol = LeafMarker;
40
41    fn from_channel(inner: fidl::Channel) -> Self {
42        Self::new(inner)
43    }
44
45    fn into_channel(self) -> fidl::Channel {
46        self.client.into_channel()
47    }
48
49    fn as_channel(&self) -> &fidl::Channel {
50        self.client.as_channel()
51    }
52}
53
54#[cfg(target_os = "fuchsia")]
55impl LeafSynchronousProxy {
56    pub fn new(channel: fidl::Channel) -> Self {
57        let protocol_name = <LeafMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
58        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
59    }
60
61    pub fn into_channel(self) -> fidl::Channel {
62        self.client.into_channel()
63    }
64
65    /// Waits until an event arrives and returns it. It is safe for other
66    /// threads to make concurrent requests while waiting for an event.
67    pub fn wait_for_event(&self, deadline: zx::MonotonicInstant) -> Result<LeafEvent, fidl::Error> {
68        LeafEvent::decode(self.client.wait_for_event(deadline)?)
69    }
70
71    pub fn r#get_string(&self, ___deadline: zx::MonotonicInstant) -> Result<String, fidl::Error> {
72        let _response =
73            self.client.send_query::<fidl::encoding::EmptyPayload, LeafGetStringResponse>(
74                (),
75                0x2493c868aa35dd7,
76                fidl::encoding::DynamicFlags::empty(),
77                ___deadline,
78            )?;
79        Ok(_response.response)
80    }
81}
82
83#[cfg(target_os = "fuchsia")]
84impl From<LeafSynchronousProxy> for zx::Handle {
85    fn from(value: LeafSynchronousProxy) -> Self {
86        value.into_channel().into()
87    }
88}
89
90#[cfg(target_os = "fuchsia")]
91impl From<fidl::Channel> for LeafSynchronousProxy {
92    fn from(value: fidl::Channel) -> Self {
93        Self::new(value)
94    }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl fidl::endpoints::FromClient for LeafSynchronousProxy {
99    type Protocol = LeafMarker;
100
101    fn from_client(value: fidl::endpoints::ClientEnd<LeafMarker>) -> Self {
102        Self::new(value.into_channel())
103    }
104}
105
106#[derive(Debug, Clone)]
107pub struct LeafProxy {
108    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
109}
110
111impl fidl::endpoints::Proxy for LeafProxy {
112    type Protocol = LeafMarker;
113
114    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
115        Self::new(inner)
116    }
117
118    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
119        self.client.into_channel().map_err(|client| Self { client })
120    }
121
122    fn as_channel(&self) -> &::fidl::AsyncChannel {
123        self.client.as_channel()
124    }
125}
126
127impl LeafProxy {
128    /// Create a new Proxy for fuchsia.compat.runtime/Leaf.
129    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
130        let protocol_name = <LeafMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
131        Self { client: fidl::client::Client::new(channel, protocol_name) }
132    }
133
134    /// Get a Stream of events from the remote end of the protocol.
135    ///
136    /// # Panics
137    ///
138    /// Panics if the event stream was already taken.
139    pub fn take_event_stream(&self) -> LeafEventStream {
140        LeafEventStream { event_receiver: self.client.take_event_receiver() }
141    }
142
143    pub fn r#get_string(
144        &self,
145    ) -> fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect> {
146        LeafProxyInterface::r#get_string(self)
147    }
148}
149
150impl LeafProxyInterface for LeafProxy {
151    type GetStringResponseFut =
152        fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect>;
153    fn r#get_string(&self) -> Self::GetStringResponseFut {
154        fn _decode(
155            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
156        ) -> Result<String, fidl::Error> {
157            let _response = fidl::client::decode_transaction_body::<
158                LeafGetStringResponse,
159                fidl::encoding::DefaultFuchsiaResourceDialect,
160                0x2493c868aa35dd7,
161            >(_buf?)?;
162            Ok(_response.response)
163        }
164        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, String>(
165            (),
166            0x2493c868aa35dd7,
167            fidl::encoding::DynamicFlags::empty(),
168            _decode,
169        )
170    }
171}
172
173pub struct LeafEventStream {
174    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
175}
176
177impl std::marker::Unpin for LeafEventStream {}
178
179impl futures::stream::FusedStream for LeafEventStream {
180    fn is_terminated(&self) -> bool {
181        self.event_receiver.is_terminated()
182    }
183}
184
185impl futures::Stream for LeafEventStream {
186    type Item = Result<LeafEvent, fidl::Error>;
187
188    fn poll_next(
189        mut self: std::pin::Pin<&mut Self>,
190        cx: &mut std::task::Context<'_>,
191    ) -> std::task::Poll<Option<Self::Item>> {
192        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
193            &mut self.event_receiver,
194            cx
195        )?) {
196            Some(buf) => std::task::Poll::Ready(Some(LeafEvent::decode(buf))),
197            None => std::task::Poll::Ready(None),
198        }
199    }
200}
201
202#[derive(Debug)]
203pub enum LeafEvent {}
204
205impl LeafEvent {
206    /// Decodes a message buffer as a [`LeafEvent`].
207    fn decode(
208        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
209    ) -> Result<LeafEvent, 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            _ => Err(fidl::Error::UnknownOrdinal {
215                ordinal: tx_header.ordinal,
216                protocol_name: <LeafMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
217            }),
218        }
219    }
220}
221
222/// A Stream of incoming requests for fuchsia.compat.runtime/Leaf.
223pub struct LeafRequestStream {
224    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
225    is_terminated: bool,
226}
227
228impl std::marker::Unpin for LeafRequestStream {}
229
230impl futures::stream::FusedStream for LeafRequestStream {
231    fn is_terminated(&self) -> bool {
232        self.is_terminated
233    }
234}
235
236impl fidl::endpoints::RequestStream for LeafRequestStream {
237    type Protocol = LeafMarker;
238    type ControlHandle = LeafControlHandle;
239
240    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
241        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
242    }
243
244    fn control_handle(&self) -> Self::ControlHandle {
245        LeafControlHandle { inner: self.inner.clone() }
246    }
247
248    fn into_inner(
249        self,
250    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
251    {
252        (self.inner, self.is_terminated)
253    }
254
255    fn from_inner(
256        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
257        is_terminated: bool,
258    ) -> Self {
259        Self { inner, is_terminated }
260    }
261}
262
263impl futures::Stream for LeafRequestStream {
264    type Item = Result<LeafRequest, fidl::Error>;
265
266    fn poll_next(
267        mut self: std::pin::Pin<&mut Self>,
268        cx: &mut std::task::Context<'_>,
269    ) -> std::task::Poll<Option<Self::Item>> {
270        let this = &mut *self;
271        if this.inner.check_shutdown(cx) {
272            this.is_terminated = true;
273            return std::task::Poll::Ready(None);
274        }
275        if this.is_terminated {
276            panic!("polled LeafRequestStream after completion");
277        }
278        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
279            |bytes, handles| {
280                match this.inner.channel().read_etc(cx, bytes, handles) {
281                    std::task::Poll::Ready(Ok(())) => {}
282                    std::task::Poll::Pending => return std::task::Poll::Pending,
283                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
284                        this.is_terminated = true;
285                        return std::task::Poll::Ready(None);
286                    }
287                    std::task::Poll::Ready(Err(e)) => {
288                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
289                            e.into(),
290                        ))))
291                    }
292                }
293
294                // A message has been received from the channel
295                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
296
297                std::task::Poll::Ready(Some(match header.ordinal {
298                    0x2493c868aa35dd7 => {
299                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
300                        let mut req = fidl::new_empty!(
301                            fidl::encoding::EmptyPayload,
302                            fidl::encoding::DefaultFuchsiaResourceDialect
303                        );
304                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
305                        let control_handle = LeafControlHandle { inner: this.inner.clone() };
306                        Ok(LeafRequest::GetString {
307                            responder: LeafGetStringResponder {
308                                control_handle: std::mem::ManuallyDrop::new(control_handle),
309                                tx_id: header.tx_id,
310                            },
311                        })
312                    }
313                    _ => Err(fidl::Error::UnknownOrdinal {
314                        ordinal: header.ordinal,
315                        protocol_name: <LeafMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
316                    }),
317                }))
318            },
319        )
320    }
321}
322
323#[derive(Debug)]
324pub enum LeafRequest {
325    GetString { responder: LeafGetStringResponder },
326}
327
328impl LeafRequest {
329    #[allow(irrefutable_let_patterns)]
330    pub fn into_get_string(self) -> Option<(LeafGetStringResponder)> {
331        if let LeafRequest::GetString { responder } = self {
332            Some((responder))
333        } else {
334            None
335        }
336    }
337
338    /// Name of the method defined in FIDL
339    pub fn method_name(&self) -> &'static str {
340        match *self {
341            LeafRequest::GetString { .. } => "get_string",
342        }
343    }
344}
345
346#[derive(Debug, Clone)]
347pub struct LeafControlHandle {
348    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
349}
350
351impl fidl::endpoints::ControlHandle for LeafControlHandle {
352    fn shutdown(&self) {
353        self.inner.shutdown()
354    }
355    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
356        self.inner.shutdown_with_epitaph(status)
357    }
358
359    fn is_closed(&self) -> bool {
360        self.inner.channel().is_closed()
361    }
362    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
363        self.inner.channel().on_closed()
364    }
365
366    #[cfg(target_os = "fuchsia")]
367    fn signal_peer(
368        &self,
369        clear_mask: zx::Signals,
370        set_mask: zx::Signals,
371    ) -> Result<(), zx_status::Status> {
372        use fidl::Peered;
373        self.inner.channel().signal_peer(clear_mask, set_mask)
374    }
375}
376
377impl LeafControlHandle {}
378
379#[must_use = "FIDL methods require a response to be sent"]
380#[derive(Debug)]
381pub struct LeafGetStringResponder {
382    control_handle: std::mem::ManuallyDrop<LeafControlHandle>,
383    tx_id: u32,
384}
385
386/// Set the the channel to be shutdown (see [`LeafControlHandle::shutdown`])
387/// if the responder is dropped without sending a response, so that the client
388/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
389impl std::ops::Drop for LeafGetStringResponder {
390    fn drop(&mut self) {
391        self.control_handle.shutdown();
392        // Safety: drops once, never accessed again
393        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
394    }
395}
396
397impl fidl::endpoints::Responder for LeafGetStringResponder {
398    type ControlHandle = LeafControlHandle;
399
400    fn control_handle(&self) -> &LeafControlHandle {
401        &self.control_handle
402    }
403
404    fn drop_without_shutdown(mut self) {
405        // Safety: drops once, never accessed again due to mem::forget
406        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
407        // Prevent Drop from running (which would shut down the channel)
408        std::mem::forget(self);
409    }
410}
411
412impl LeafGetStringResponder {
413    /// Sends a response to the FIDL transaction.
414    ///
415    /// Sets the channel to shutdown if an error occurs.
416    pub fn send(self, mut response: &str) -> Result<(), fidl::Error> {
417        let _result = self.send_raw(response);
418        if _result.is_err() {
419            self.control_handle.shutdown();
420        }
421        self.drop_without_shutdown();
422        _result
423    }
424
425    /// Similar to "send" but does not shutdown the channel if an error occurs.
426    pub fn send_no_shutdown_on_err(self, mut response: &str) -> Result<(), fidl::Error> {
427        let _result = self.send_raw(response);
428        self.drop_without_shutdown();
429        _result
430    }
431
432    fn send_raw(&self, mut response: &str) -> Result<(), fidl::Error> {
433        self.control_handle.inner.send::<LeafGetStringResponse>(
434            (response,),
435            self.tx_id,
436            0x2493c868aa35dd7,
437            fidl::encoding::DynamicFlags::empty(),
438        )
439    }
440}
441
442mod internal {
443    use super::*;
444}