fidl_fuchsia_trf_mockcontrol_reversertrftest/
fidl_fuchsia_trf_mockcontrol_reversertrftest.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_trf_mockcontrol_reversertrftest_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct MockReplacerControlMarker;
16
17impl fidl::endpoints::ProtocolMarker for MockReplacerControlMarker {
18 type Proxy = MockReplacerControlProxy;
19 type RequestStream = MockReplacerControlRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = MockReplacerControlSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.trf.mockcontrol.reversertrftest.MockReplacerControl";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for MockReplacerControlMarker {}
26
27pub trait MockReplacerControlProxyInterface: Send + Sync {
28 type SetReplacementResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29 fn r#set_replacement(&self, target: &str, replacement: &str)
30 -> Self::SetReplacementResponseFut;
31}
32#[derive(Debug)]
33#[cfg(target_os = "fuchsia")]
34pub struct MockReplacerControlSynchronousProxy {
35 client: fidl::client::sync::Client,
36}
37
38#[cfg(target_os = "fuchsia")]
39impl fidl::endpoints::SynchronousProxy for MockReplacerControlSynchronousProxy {
40 type Proxy = MockReplacerControlProxy;
41 type Protocol = MockReplacerControlMarker;
42
43 fn from_channel(inner: fidl::Channel) -> Self {
44 Self::new(inner)
45 }
46
47 fn into_channel(self) -> fidl::Channel {
48 self.client.into_channel()
49 }
50
51 fn as_channel(&self) -> &fidl::Channel {
52 self.client.as_channel()
53 }
54}
55
56#[cfg(target_os = "fuchsia")]
57impl MockReplacerControlSynchronousProxy {
58 pub fn new(channel: fidl::Channel) -> Self {
59 Self { client: fidl::client::sync::Client::new(channel) }
60 }
61
62 pub fn into_channel(self) -> fidl::Channel {
63 self.client.into_channel()
64 }
65
66 pub fn wait_for_event(
69 &self,
70 deadline: zx::MonotonicInstant,
71 ) -> Result<MockReplacerControlEvent, fidl::Error> {
72 MockReplacerControlEvent::decode(
73 self.client.wait_for_event::<MockReplacerControlMarker>(deadline)?,
74 )
75 }
76
77 pub fn r#set_replacement(
78 &self,
79 mut target: &str,
80 mut replacement: &str,
81 ___deadline: zx::MonotonicInstant,
82 ) -> Result<(), fidl::Error> {
83 let _response = self.client.send_query::<
84 MockReplacerControlSetReplacementRequest,
85 fidl::encoding::EmptyPayload,
86 MockReplacerControlMarker,
87 >(
88 (target, replacement,),
89 0x266f2bdf5b12edbf,
90 fidl::encoding::DynamicFlags::empty(),
91 ___deadline,
92 )?;
93 Ok(_response)
94 }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl From<MockReplacerControlSynchronousProxy> for zx::NullableHandle {
99 fn from(value: MockReplacerControlSynchronousProxy) -> Self {
100 value.into_channel().into()
101 }
102}
103
104#[cfg(target_os = "fuchsia")]
105impl From<fidl::Channel> for MockReplacerControlSynchronousProxy {
106 fn from(value: fidl::Channel) -> Self {
107 Self::new(value)
108 }
109}
110
111#[cfg(target_os = "fuchsia")]
112impl fidl::endpoints::FromClient for MockReplacerControlSynchronousProxy {
113 type Protocol = MockReplacerControlMarker;
114
115 fn from_client(value: fidl::endpoints::ClientEnd<MockReplacerControlMarker>) -> Self {
116 Self::new(value.into_channel())
117 }
118}
119
120#[derive(Debug, Clone)]
121pub struct MockReplacerControlProxy {
122 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
123}
124
125impl fidl::endpoints::Proxy for MockReplacerControlProxy {
126 type Protocol = MockReplacerControlMarker;
127
128 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
129 Self::new(inner)
130 }
131
132 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
133 self.client.into_channel().map_err(|client| Self { client })
134 }
135
136 fn as_channel(&self) -> &::fidl::AsyncChannel {
137 self.client.as_channel()
138 }
139}
140
141impl MockReplacerControlProxy {
142 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
144 let protocol_name =
145 <MockReplacerControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
146 Self { client: fidl::client::Client::new(channel, protocol_name) }
147 }
148
149 pub fn take_event_stream(&self) -> MockReplacerControlEventStream {
155 MockReplacerControlEventStream { event_receiver: self.client.take_event_receiver() }
156 }
157
158 pub fn r#set_replacement(
159 &self,
160 mut target: &str,
161 mut replacement: &str,
162 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
163 MockReplacerControlProxyInterface::r#set_replacement(self, target, replacement)
164 }
165}
166
167impl MockReplacerControlProxyInterface for MockReplacerControlProxy {
168 type SetReplacementResponseFut =
169 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
170 fn r#set_replacement(
171 &self,
172 mut target: &str,
173 mut replacement: &str,
174 ) -> Self::SetReplacementResponseFut {
175 fn _decode(
176 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
177 ) -> Result<(), fidl::Error> {
178 let _response = fidl::client::decode_transaction_body::<
179 fidl::encoding::EmptyPayload,
180 fidl::encoding::DefaultFuchsiaResourceDialect,
181 0x266f2bdf5b12edbf,
182 >(_buf?)?;
183 Ok(_response)
184 }
185 self.client.send_query_and_decode::<MockReplacerControlSetReplacementRequest, ()>(
186 (target, replacement),
187 0x266f2bdf5b12edbf,
188 fidl::encoding::DynamicFlags::empty(),
189 _decode,
190 )
191 }
192}
193
194pub struct MockReplacerControlEventStream {
195 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
196}
197
198impl std::marker::Unpin for MockReplacerControlEventStream {}
199
200impl futures::stream::FusedStream for MockReplacerControlEventStream {
201 fn is_terminated(&self) -> bool {
202 self.event_receiver.is_terminated()
203 }
204}
205
206impl futures::Stream for MockReplacerControlEventStream {
207 type Item = Result<MockReplacerControlEvent, fidl::Error>;
208
209 fn poll_next(
210 mut self: std::pin::Pin<&mut Self>,
211 cx: &mut std::task::Context<'_>,
212 ) -> std::task::Poll<Option<Self::Item>> {
213 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
214 &mut self.event_receiver,
215 cx
216 )?) {
217 Some(buf) => std::task::Poll::Ready(Some(MockReplacerControlEvent::decode(buf))),
218 None => std::task::Poll::Ready(None),
219 }
220 }
221}
222
223#[derive(Debug)]
224pub enum MockReplacerControlEvent {}
225
226impl MockReplacerControlEvent {
227 fn decode(
229 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
230 ) -> Result<MockReplacerControlEvent, fidl::Error> {
231 let (bytes, _handles) = buf.split_mut();
232 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
233 debug_assert_eq!(tx_header.tx_id, 0);
234 match tx_header.ordinal {
235 _ => Err(fidl::Error::UnknownOrdinal {
236 ordinal: tx_header.ordinal,
237 protocol_name:
238 <MockReplacerControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
239 }),
240 }
241 }
242}
243
244pub struct MockReplacerControlRequestStream {
246 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
247 is_terminated: bool,
248}
249
250impl std::marker::Unpin for MockReplacerControlRequestStream {}
251
252impl futures::stream::FusedStream for MockReplacerControlRequestStream {
253 fn is_terminated(&self) -> bool {
254 self.is_terminated
255 }
256}
257
258impl fidl::endpoints::RequestStream for MockReplacerControlRequestStream {
259 type Protocol = MockReplacerControlMarker;
260 type ControlHandle = MockReplacerControlControlHandle;
261
262 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
263 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
264 }
265
266 fn control_handle(&self) -> Self::ControlHandle {
267 MockReplacerControlControlHandle { inner: self.inner.clone() }
268 }
269
270 fn into_inner(
271 self,
272 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
273 {
274 (self.inner, self.is_terminated)
275 }
276
277 fn from_inner(
278 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
279 is_terminated: bool,
280 ) -> Self {
281 Self { inner, is_terminated }
282 }
283}
284
285impl futures::Stream for MockReplacerControlRequestStream {
286 type Item = Result<MockReplacerControlRequest, fidl::Error>;
287
288 fn poll_next(
289 mut self: std::pin::Pin<&mut Self>,
290 cx: &mut std::task::Context<'_>,
291 ) -> std::task::Poll<Option<Self::Item>> {
292 let this = &mut *self;
293 if this.inner.check_shutdown(cx) {
294 this.is_terminated = true;
295 return std::task::Poll::Ready(None);
296 }
297 if this.is_terminated {
298 panic!("polled MockReplacerControlRequestStream after completion");
299 }
300 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
301 |bytes, handles| {
302 match this.inner.channel().read_etc(cx, bytes, handles) {
303 std::task::Poll::Ready(Ok(())) => {}
304 std::task::Poll::Pending => return std::task::Poll::Pending,
305 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
306 this.is_terminated = true;
307 return std::task::Poll::Ready(None);
308 }
309 std::task::Poll::Ready(Err(e)) => {
310 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
311 e.into(),
312 ))));
313 }
314 }
315
316 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
318
319 std::task::Poll::Ready(Some(match header.ordinal {
320 0x266f2bdf5b12edbf => {
321 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
322 let mut req = fidl::new_empty!(MockReplacerControlSetReplacementRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
323 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<MockReplacerControlSetReplacementRequest>(&header, _body_bytes, handles, &mut req)?;
324 let control_handle = MockReplacerControlControlHandle {
325 inner: this.inner.clone(),
326 };
327 Ok(MockReplacerControlRequest::SetReplacement {target: req.target,
328replacement: req.replacement,
329
330 responder: MockReplacerControlSetReplacementResponder {
331 control_handle: std::mem::ManuallyDrop::new(control_handle),
332 tx_id: header.tx_id,
333 },
334 })
335 }
336 _ => Err(fidl::Error::UnknownOrdinal {
337 ordinal: header.ordinal,
338 protocol_name: <MockReplacerControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
339 }),
340 }))
341 },
342 )
343 }
344}
345
346#[derive(Debug)]
347pub enum MockReplacerControlRequest {
348 SetReplacement {
349 target: String,
350 replacement: String,
351 responder: MockReplacerControlSetReplacementResponder,
352 },
353}
354
355impl MockReplacerControlRequest {
356 #[allow(irrefutable_let_patterns)]
357 pub fn into_set_replacement(
358 self,
359 ) -> Option<(String, String, MockReplacerControlSetReplacementResponder)> {
360 if let MockReplacerControlRequest::SetReplacement { target, replacement, responder } = self
361 {
362 Some((target, replacement, responder))
363 } else {
364 None
365 }
366 }
367
368 pub fn method_name(&self) -> &'static str {
370 match *self {
371 MockReplacerControlRequest::SetReplacement { .. } => "set_replacement",
372 }
373 }
374}
375
376#[derive(Debug, Clone)]
377pub struct MockReplacerControlControlHandle {
378 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
379}
380
381impl MockReplacerControlControlHandle {
382 pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
383 self.inner.shutdown_with_epitaph(status.into())
384 }
385}
386
387impl fidl::endpoints::ControlHandle for MockReplacerControlControlHandle {
388 fn shutdown(&self) {
389 self.inner.shutdown()
390 }
391
392 fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
393 self.inner.shutdown_with_epitaph(status)
394 }
395
396 fn is_closed(&self) -> bool {
397 self.inner.channel().is_closed()
398 }
399 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
400 self.inner.channel().on_closed()
401 }
402
403 #[cfg(target_os = "fuchsia")]
404 fn signal_peer(
405 &self,
406 clear_mask: zx::Signals,
407 set_mask: zx::Signals,
408 ) -> Result<(), zx_status::Status> {
409 use fidl::Peered;
410 self.inner.channel().signal_peer(clear_mask, set_mask)
411 }
412}
413
414impl MockReplacerControlControlHandle {}
415
416#[must_use = "FIDL methods require a response to be sent"]
417#[derive(Debug)]
418pub struct MockReplacerControlSetReplacementResponder {
419 control_handle: std::mem::ManuallyDrop<MockReplacerControlControlHandle>,
420 tx_id: u32,
421}
422
423impl std::ops::Drop for MockReplacerControlSetReplacementResponder {
427 fn drop(&mut self) {
428 self.control_handle.shutdown();
429 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
431 }
432}
433
434impl fidl::endpoints::Responder for MockReplacerControlSetReplacementResponder {
435 type ControlHandle = MockReplacerControlControlHandle;
436
437 fn control_handle(&self) -> &MockReplacerControlControlHandle {
438 &self.control_handle
439 }
440
441 fn drop_without_shutdown(mut self) {
442 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
444 std::mem::forget(self);
446 }
447}
448
449impl MockReplacerControlSetReplacementResponder {
450 pub fn send(self) -> Result<(), fidl::Error> {
454 let _result = self.send_raw();
455 if _result.is_err() {
456 self.control_handle.shutdown();
457 }
458 self.drop_without_shutdown();
459 _result
460 }
461
462 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
464 let _result = self.send_raw();
465 self.drop_without_shutdown();
466 _result
467 }
468
469 fn send_raw(&self) -> Result<(), fidl::Error> {
470 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
471 (),
472 self.tx_id,
473 0x266f2bdf5b12edbf,
474 fidl::encoding::DynamicFlags::empty(),
475 )
476 }
477}
478
479mod internal {
480 use super::*;
481}