Skip to main content

fdomain_test_placeholders/
fdomain_test_placeholders.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 fdomain_client::fidl::{ControlHandle as _, FDomainFlexibleIntoResult as _, Responder as _};
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9pub use fidl_test_placeholders__common::*;
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
14pub struct EchoMarker;
15
16impl fdomain_client::fidl::ProtocolMarker for EchoMarker {
17    type Proxy = EchoProxy;
18    type RequestStream = EchoRequestStream;
19
20    const DEBUG_NAME: &'static str = "test.placeholders.Echo";
21}
22impl fdomain_client::fidl::DiscoverableProtocolMarker for EchoMarker {}
23
24pub trait EchoProxyInterface: Send + Sync {
25    type EchoStringResponseFut: std::future::Future<Output = Result<Option<String>, fidl::Error>>
26        + Send;
27    fn r#echo_string(&self, value: Option<&str>) -> Self::EchoStringResponseFut;
28}
29
30#[derive(Debug, Clone)]
31pub struct EchoProxy {
32    client: fidl::client::Client<fdomain_client::fidl::FDomainResourceDialect>,
33}
34
35impl fdomain_client::fidl::Proxy for EchoProxy {
36    type Protocol = EchoMarker;
37
38    fn from_channel(inner: fdomain_client::Channel) -> Self {
39        Self::new(inner)
40    }
41
42    fn into_channel(self) -> Result<fdomain_client::Channel, Self> {
43        self.client.into_channel().map_err(|client| Self { client })
44    }
45
46    fn as_channel(&self) -> &fdomain_client::Channel {
47        self.client.as_channel()
48    }
49}
50
51impl EchoProxy {
52    /// Create a new Proxy for test.placeholders/Echo.
53    pub fn new(channel: fdomain_client::Channel) -> Self {
54        let protocol_name = <EchoMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME;
55        Self { client: fidl::client::Client::new(channel, protocol_name) }
56    }
57
58    /// Get a Stream of events from the remote end of the protocol.
59    ///
60    /// # Panics
61    ///
62    /// Panics if the event stream was already taken.
63    pub fn take_event_stream(&self) -> EchoEventStream {
64        EchoEventStream { event_receiver: self.client.take_event_receiver() }
65    }
66
67    pub fn r#echo_string(
68        &self,
69        mut value: Option<&str>,
70    ) -> fidl::client::QueryResponseFut<Option<String>, fdomain_client::fidl::FDomainResourceDialect>
71    {
72        EchoProxyInterface::r#echo_string(self, value)
73    }
74}
75
76impl EchoProxyInterface for EchoProxy {
77    type EchoStringResponseFut = fidl::client::QueryResponseFut<
78        Option<String>,
79        fdomain_client::fidl::FDomainResourceDialect,
80    >;
81    fn r#echo_string(&self, mut value: Option<&str>) -> Self::EchoStringResponseFut {
82        fn _decode(
83            mut _buf: Result<<fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
84        ) -> Result<Option<String>, fidl::Error> {
85            let _response = fidl::client::decode_transaction_body::<
86                EchoEchoStringResponse,
87                fdomain_client::fidl::FDomainResourceDialect,
88                0x39f9ac471d0ec540,
89            >(_buf?)?;
90            Ok(_response.response)
91        }
92        self.client.send_query_and_decode::<EchoEchoStringRequest, Option<String>>(
93            (value,),
94            0x39f9ac471d0ec540,
95            fidl::encoding::DynamicFlags::empty(),
96            _decode,
97        )
98    }
99}
100
101pub struct EchoEventStream {
102    event_receiver: fidl::client::EventReceiver<fdomain_client::fidl::FDomainResourceDialect>,
103}
104
105impl std::marker::Unpin for EchoEventStream {}
106
107impl futures::stream::FusedStream for EchoEventStream {
108    fn is_terminated(&self) -> bool {
109        self.event_receiver.is_terminated()
110    }
111}
112
113impl futures::Stream for EchoEventStream {
114    type Item = Result<EchoEvent, fidl::Error>;
115
116    fn poll_next(
117        mut self: std::pin::Pin<&mut Self>,
118        cx: &mut std::task::Context<'_>,
119    ) -> std::task::Poll<Option<Self::Item>> {
120        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
121            &mut self.event_receiver,
122            cx
123        )?) {
124            Some(buf) => std::task::Poll::Ready(Some(EchoEvent::decode(buf))),
125            None => std::task::Poll::Ready(None),
126        }
127    }
128}
129
130#[derive(Debug)]
131pub enum EchoEvent {}
132
133impl EchoEvent {
134    /// Decodes a message buffer as a [`EchoEvent`].
135    fn decode(
136        mut buf: <fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
137    ) -> Result<EchoEvent, fidl::Error> {
138        let (bytes, _handles) = buf.split_mut();
139        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
140        debug_assert_eq!(tx_header.tx_id, 0);
141        match tx_header.ordinal {
142            _ => Err(fidl::Error::UnknownOrdinal {
143                ordinal: tx_header.ordinal,
144                protocol_name: <EchoMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
145            }),
146        }
147    }
148}
149
150/// A Stream of incoming requests for test.placeholders/Echo.
151pub struct EchoRequestStream {
152    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
153    is_terminated: bool,
154}
155
156impl std::marker::Unpin for EchoRequestStream {}
157
158impl futures::stream::FusedStream for EchoRequestStream {
159    fn is_terminated(&self) -> bool {
160        self.is_terminated
161    }
162}
163
164impl fdomain_client::fidl::RequestStream for EchoRequestStream {
165    type Protocol = EchoMarker;
166    type ControlHandle = EchoControlHandle;
167
168    fn from_channel(channel: fdomain_client::Channel) -> Self {
169        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
170    }
171
172    fn control_handle(&self) -> Self::ControlHandle {
173        EchoControlHandle { inner: self.inner.clone() }
174    }
175
176    fn into_inner(
177        self,
178    ) -> (::std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>, bool)
179    {
180        (self.inner, self.is_terminated)
181    }
182
183    fn from_inner(
184        inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
185        is_terminated: bool,
186    ) -> Self {
187        Self { inner, is_terminated }
188    }
189}
190
191impl futures::Stream for EchoRequestStream {
192    type Item = Result<EchoRequest, fidl::Error>;
193
194    fn poll_next(
195        mut self: std::pin::Pin<&mut Self>,
196        cx: &mut std::task::Context<'_>,
197    ) -> std::task::Poll<Option<Self::Item>> {
198        let this = &mut *self;
199        if this.inner.check_shutdown(cx) {
200            this.is_terminated = true;
201            return std::task::Poll::Ready(None);
202        }
203        if this.is_terminated {
204            panic!("polled EchoRequestStream after completion");
205        }
206        fidl::encoding::with_tls_decode_buf::<_, fdomain_client::fidl::FDomainResourceDialect>(
207            |bytes, handles| {
208                match this.inner.channel().read_etc(cx, bytes, handles) {
209                    std::task::Poll::Ready(Ok(())) => {}
210                    std::task::Poll::Pending => return std::task::Poll::Pending,
211                    std::task::Poll::Ready(Err(None)) => {
212                        this.is_terminated = true;
213                        return std::task::Poll::Ready(None);
214                    }
215                    std::task::Poll::Ready(Err(Some(e))) => {
216                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
217                            e.into(),
218                        ))));
219                    }
220                }
221
222                // A message has been received from the channel
223                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
224
225                std::task::Poll::Ready(Some(match header.ordinal {
226                    0x39f9ac471d0ec540 => {
227                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
228                        let mut req = fidl::new_empty!(
229                            EchoEchoStringRequest,
230                            fdomain_client::fidl::FDomainResourceDialect
231                        );
232                        fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<EchoEchoStringRequest>(&header, _body_bytes, handles, &mut req)?;
233                        let control_handle = EchoControlHandle { inner: this.inner.clone() };
234                        Ok(EchoRequest::EchoString {
235                            value: req.value,
236
237                            responder: EchoEchoStringResponder {
238                                control_handle: std::mem::ManuallyDrop::new(control_handle),
239                                tx_id: header.tx_id,
240                            },
241                        })
242                    }
243                    _ => Err(fidl::Error::UnknownOrdinal {
244                        ordinal: header.ordinal,
245                        protocol_name:
246                            <EchoMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
247                    }),
248                }))
249            },
250        )
251    }
252}
253
254#[derive(Debug)]
255pub enum EchoRequest {
256    EchoString { value: Option<String>, responder: EchoEchoStringResponder },
257}
258
259impl EchoRequest {
260    #[allow(irrefutable_let_patterns)]
261    pub fn into_echo_string(self) -> Option<(Option<String>, EchoEchoStringResponder)> {
262        if let EchoRequest::EchoString { value, responder } = self {
263            Some((value, responder))
264        } else {
265            None
266        }
267    }
268
269    /// Name of the method defined in FIDL
270    pub fn method_name(&self) -> &'static str {
271        match *self {
272            EchoRequest::EchoString { .. } => "echo_string",
273        }
274    }
275}
276
277#[derive(Debug, Clone)]
278pub struct EchoControlHandle {
279    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
280}
281
282impl fdomain_client::fidl::ControlHandle for EchoControlHandle {
283    fn shutdown(&self) {
284        self.inner.shutdown()
285    }
286
287    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
288        self.inner.shutdown_with_epitaph(status)
289    }
290
291    fn is_closed(&self) -> bool {
292        self.inner.channel().is_closed()
293    }
294    fn on_closed(&self) -> fdomain_client::OnFDomainSignals {
295        self.inner.channel().on_closed()
296    }
297}
298
299impl EchoControlHandle {}
300
301#[must_use = "FIDL methods require a response to be sent"]
302#[derive(Debug)]
303pub struct EchoEchoStringResponder {
304    control_handle: std::mem::ManuallyDrop<EchoControlHandle>,
305    tx_id: u32,
306}
307
308/// Set the the channel to be shutdown (see [`EchoControlHandle::shutdown`])
309/// if the responder is dropped without sending a response, so that the client
310/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
311impl std::ops::Drop for EchoEchoStringResponder {
312    fn drop(&mut self) {
313        self.control_handle.shutdown();
314        // Safety: drops once, never accessed again
315        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
316    }
317}
318
319impl fdomain_client::fidl::Responder for EchoEchoStringResponder {
320    type ControlHandle = EchoControlHandle;
321
322    fn control_handle(&self) -> &EchoControlHandle {
323        &self.control_handle
324    }
325
326    fn drop_without_shutdown(mut self) {
327        // Safety: drops once, never accessed again due to mem::forget
328        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
329        // Prevent Drop from running (which would shut down the channel)
330        std::mem::forget(self);
331    }
332}
333
334impl EchoEchoStringResponder {
335    /// Sends a response to the FIDL transaction.
336    ///
337    /// Sets the channel to shutdown if an error occurs.
338    pub fn send(self, mut response: Option<&str>) -> Result<(), fidl::Error> {
339        let _result = self.send_raw(response);
340        if _result.is_err() {
341            self.control_handle.shutdown();
342        }
343        self.drop_without_shutdown();
344        _result
345    }
346
347    /// Similar to "send" but does not shutdown the channel if an error occurs.
348    pub fn send_no_shutdown_on_err(self, mut response: Option<&str>) -> Result<(), fidl::Error> {
349        let _result = self.send_raw(response);
350        self.drop_without_shutdown();
351        _result
352    }
353
354    fn send_raw(&self, mut response: Option<&str>) -> Result<(), fidl::Error> {
355        self.control_handle.inner.send::<EchoEchoStringResponse>(
356            (response,),
357            self.tx_id,
358            0x39f9ac471d0ec540,
359            fidl::encoding::DynamicFlags::empty(),
360        )
361    }
362}
363
364mod internal {
365    use super::*;
366}