Skip to main content

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