fidl_fuchsia_compat_runtime/
fidl_fuchsia_compat_runtime.rs1#![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 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#[derive(Debug, Clone)]
84pub struct LeafProxy {
85 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
86}
87
88impl fidl::endpoints::Proxy for LeafProxy {
89 type Protocol = LeafMarker;
90
91 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
92 Self::new(inner)
93 }
94
95 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
96 self.client.into_channel().map_err(|client| Self { client })
97 }
98
99 fn as_channel(&self) -> &::fidl::AsyncChannel {
100 self.client.as_channel()
101 }
102}
103
104impl LeafProxy {
105 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
107 let protocol_name = <LeafMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
108 Self { client: fidl::client::Client::new(channel, protocol_name) }
109 }
110
111 pub fn take_event_stream(&self) -> LeafEventStream {
117 LeafEventStream { event_receiver: self.client.take_event_receiver() }
118 }
119
120 pub fn r#get_string(
121 &self,
122 ) -> fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect> {
123 LeafProxyInterface::r#get_string(self)
124 }
125}
126
127impl LeafProxyInterface for LeafProxy {
128 type GetStringResponseFut =
129 fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect>;
130 fn r#get_string(&self) -> Self::GetStringResponseFut {
131 fn _decode(
132 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
133 ) -> Result<String, fidl::Error> {
134 let _response = fidl::client::decode_transaction_body::<
135 LeafGetStringResponse,
136 fidl::encoding::DefaultFuchsiaResourceDialect,
137 0x2493c868aa35dd7,
138 >(_buf?)?;
139 Ok(_response.response)
140 }
141 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, String>(
142 (),
143 0x2493c868aa35dd7,
144 fidl::encoding::DynamicFlags::empty(),
145 _decode,
146 )
147 }
148}
149
150pub struct LeafEventStream {
151 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
152}
153
154impl std::marker::Unpin for LeafEventStream {}
155
156impl futures::stream::FusedStream for LeafEventStream {
157 fn is_terminated(&self) -> bool {
158 self.event_receiver.is_terminated()
159 }
160}
161
162impl futures::Stream for LeafEventStream {
163 type Item = Result<LeafEvent, fidl::Error>;
164
165 fn poll_next(
166 mut self: std::pin::Pin<&mut Self>,
167 cx: &mut std::task::Context<'_>,
168 ) -> std::task::Poll<Option<Self::Item>> {
169 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
170 &mut self.event_receiver,
171 cx
172 )?) {
173 Some(buf) => std::task::Poll::Ready(Some(LeafEvent::decode(buf))),
174 None => std::task::Poll::Ready(None),
175 }
176 }
177}
178
179#[derive(Debug)]
180pub enum LeafEvent {}
181
182impl LeafEvent {
183 fn decode(
185 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
186 ) -> Result<LeafEvent, fidl::Error> {
187 let (bytes, _handles) = buf.split_mut();
188 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
189 debug_assert_eq!(tx_header.tx_id, 0);
190 match tx_header.ordinal {
191 _ => Err(fidl::Error::UnknownOrdinal {
192 ordinal: tx_header.ordinal,
193 protocol_name: <LeafMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
194 }),
195 }
196 }
197}
198
199pub struct LeafRequestStream {
201 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
202 is_terminated: bool,
203}
204
205impl std::marker::Unpin for LeafRequestStream {}
206
207impl futures::stream::FusedStream for LeafRequestStream {
208 fn is_terminated(&self) -> bool {
209 self.is_terminated
210 }
211}
212
213impl fidl::endpoints::RequestStream for LeafRequestStream {
214 type Protocol = LeafMarker;
215 type ControlHandle = LeafControlHandle;
216
217 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
218 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
219 }
220
221 fn control_handle(&self) -> Self::ControlHandle {
222 LeafControlHandle { inner: self.inner.clone() }
223 }
224
225 fn into_inner(
226 self,
227 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
228 {
229 (self.inner, self.is_terminated)
230 }
231
232 fn from_inner(
233 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
234 is_terminated: bool,
235 ) -> Self {
236 Self { inner, is_terminated }
237 }
238}
239
240impl futures::Stream for LeafRequestStream {
241 type Item = Result<LeafRequest, fidl::Error>;
242
243 fn poll_next(
244 mut self: std::pin::Pin<&mut Self>,
245 cx: &mut std::task::Context<'_>,
246 ) -> std::task::Poll<Option<Self::Item>> {
247 let this = &mut *self;
248 if this.inner.check_shutdown(cx) {
249 this.is_terminated = true;
250 return std::task::Poll::Ready(None);
251 }
252 if this.is_terminated {
253 panic!("polled LeafRequestStream after completion");
254 }
255 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
256 |bytes, handles| {
257 match this.inner.channel().read_etc(cx, bytes, handles) {
258 std::task::Poll::Ready(Ok(())) => {}
259 std::task::Poll::Pending => return std::task::Poll::Pending,
260 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
261 this.is_terminated = true;
262 return std::task::Poll::Ready(None);
263 }
264 std::task::Poll::Ready(Err(e)) => {
265 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
266 e.into(),
267 ))))
268 }
269 }
270
271 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
273
274 std::task::Poll::Ready(Some(match header.ordinal {
275 0x2493c868aa35dd7 => {
276 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
277 let mut req = fidl::new_empty!(
278 fidl::encoding::EmptyPayload,
279 fidl::encoding::DefaultFuchsiaResourceDialect
280 );
281 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
282 let control_handle = LeafControlHandle { inner: this.inner.clone() };
283 Ok(LeafRequest::GetString {
284 responder: LeafGetStringResponder {
285 control_handle: std::mem::ManuallyDrop::new(control_handle),
286 tx_id: header.tx_id,
287 },
288 })
289 }
290 _ => Err(fidl::Error::UnknownOrdinal {
291 ordinal: header.ordinal,
292 protocol_name: <LeafMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
293 }),
294 }))
295 },
296 )
297 }
298}
299
300#[derive(Debug)]
301pub enum LeafRequest {
302 GetString { responder: LeafGetStringResponder },
303}
304
305impl LeafRequest {
306 #[allow(irrefutable_let_patterns)]
307 pub fn into_get_string(self) -> Option<(LeafGetStringResponder)> {
308 if let LeafRequest::GetString { responder } = self {
309 Some((responder))
310 } else {
311 None
312 }
313 }
314
315 pub fn method_name(&self) -> &'static str {
317 match *self {
318 LeafRequest::GetString { .. } => "get_string",
319 }
320 }
321}
322
323#[derive(Debug, Clone)]
324pub struct LeafControlHandle {
325 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
326}
327
328impl fidl::endpoints::ControlHandle for LeafControlHandle {
329 fn shutdown(&self) {
330 self.inner.shutdown()
331 }
332 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
333 self.inner.shutdown_with_epitaph(status)
334 }
335
336 fn is_closed(&self) -> bool {
337 self.inner.channel().is_closed()
338 }
339 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
340 self.inner.channel().on_closed()
341 }
342
343 #[cfg(target_os = "fuchsia")]
344 fn signal_peer(
345 &self,
346 clear_mask: zx::Signals,
347 set_mask: zx::Signals,
348 ) -> Result<(), zx_status::Status> {
349 use fidl::Peered;
350 self.inner.channel().signal_peer(clear_mask, set_mask)
351 }
352}
353
354impl LeafControlHandle {}
355
356#[must_use = "FIDL methods require a response to be sent"]
357#[derive(Debug)]
358pub struct LeafGetStringResponder {
359 control_handle: std::mem::ManuallyDrop<LeafControlHandle>,
360 tx_id: u32,
361}
362
363impl std::ops::Drop for LeafGetStringResponder {
367 fn drop(&mut self) {
368 self.control_handle.shutdown();
369 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
371 }
372}
373
374impl fidl::endpoints::Responder for LeafGetStringResponder {
375 type ControlHandle = LeafControlHandle;
376
377 fn control_handle(&self) -> &LeafControlHandle {
378 &self.control_handle
379 }
380
381 fn drop_without_shutdown(mut self) {
382 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
384 std::mem::forget(self);
386 }
387}
388
389impl LeafGetStringResponder {
390 pub fn send(self, mut response: &str) -> Result<(), fidl::Error> {
394 let _result = self.send_raw(response);
395 if _result.is_err() {
396 self.control_handle.shutdown();
397 }
398 self.drop_without_shutdown();
399 _result
400 }
401
402 pub fn send_no_shutdown_on_err(self, mut response: &str) -> Result<(), fidl::Error> {
404 let _result = self.send_raw(response);
405 self.drop_without_shutdown();
406 _result
407 }
408
409 fn send_raw(&self, mut response: &str) -> Result<(), fidl::Error> {
410 self.control_handle.inner.send::<LeafGetStringResponse>(
411 (response,),
412 self.tx_id,
413 0x2493c868aa35dd7,
414 fidl::encoding::DynamicFlags::empty(),
415 )
416 }
417}
418
419mod internal {
420 use super::*;
421}