fidl_fuchsia_pkg_rewrite/
fidl_fuchsia_pkg_rewrite.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_pkg_rewrite_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct EditTransactionListDynamicRequest {
16    pub iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for EditTransactionListDynamicRequest
21{
22}
23
24#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
25pub struct EngineListRequest {
26    pub iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
27}
28
29impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for EngineListRequest {}
30
31#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
32pub struct EngineListStaticRequest {
33    pub iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
34}
35
36impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for EngineListStaticRequest {}
37
38#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
39pub struct EngineStartEditTransactionRequest {
40    pub transaction: fidl::endpoints::ServerEnd<EditTransactionMarker>,
41}
42
43impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
44    for EngineStartEditTransactionRequest
45{
46}
47
48#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
49pub struct EditTransactionMarker;
50
51impl fidl::endpoints::ProtocolMarker for EditTransactionMarker {
52    type Proxy = EditTransactionProxy;
53    type RequestStream = EditTransactionRequestStream;
54    #[cfg(target_os = "fuchsia")]
55    type SynchronousProxy = EditTransactionSynchronousProxy;
56
57    const DEBUG_NAME: &'static str = "(anonymous) EditTransaction";
58}
59pub type EditTransactionAddResult = Result<(), i32>;
60pub type EditTransactionCommitResult = Result<(), i32>;
61
62pub trait EditTransactionProxyInterface: Send + Sync {
63    fn r#list_dynamic(
64        &self,
65        iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
66    ) -> Result<(), fidl::Error>;
67    fn r#reset_all(&self) -> Result<(), fidl::Error>;
68    type AddResponseFut: std::future::Future<Output = Result<EditTransactionAddResult, fidl::Error>>
69        + Send;
70    fn r#add(&self, rule: &Rule) -> Self::AddResponseFut;
71    type CommitResponseFut: std::future::Future<Output = Result<EditTransactionCommitResult, fidl::Error>>
72        + Send;
73    fn r#commit(&self) -> Self::CommitResponseFut;
74}
75#[derive(Debug)]
76#[cfg(target_os = "fuchsia")]
77pub struct EditTransactionSynchronousProxy {
78    client: fidl::client::sync::Client,
79}
80
81#[cfg(target_os = "fuchsia")]
82impl fidl::endpoints::SynchronousProxy for EditTransactionSynchronousProxy {
83    type Proxy = EditTransactionProxy;
84    type Protocol = EditTransactionMarker;
85
86    fn from_channel(inner: fidl::Channel) -> Self {
87        Self::new(inner)
88    }
89
90    fn into_channel(self) -> fidl::Channel {
91        self.client.into_channel()
92    }
93
94    fn as_channel(&self) -> &fidl::Channel {
95        self.client.as_channel()
96    }
97}
98
99#[cfg(target_os = "fuchsia")]
100impl EditTransactionSynchronousProxy {
101    pub fn new(channel: fidl::Channel) -> Self {
102        let protocol_name = <EditTransactionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
103        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
104    }
105
106    pub fn into_channel(self) -> fidl::Channel {
107        self.client.into_channel()
108    }
109
110    /// Waits until an event arrives and returns it. It is safe for other
111    /// threads to make concurrent requests while waiting for an event.
112    pub fn wait_for_event(
113        &self,
114        deadline: zx::MonotonicInstant,
115    ) -> Result<EditTransactionEvent, fidl::Error> {
116        EditTransactionEvent::decode(self.client.wait_for_event(deadline)?)
117    }
118
119    /// Returns an iterator over all dynamic (editable) rewrite rules. The
120    /// iterator will reflect any changes made to the rewrite rules so far in
121    /// this transaction.
122    ///
123    /// + request `iterator` a request for an iterator.
124    pub fn r#list_dynamic(
125        &self,
126        mut iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
127    ) -> Result<(), fidl::Error> {
128        self.client.send::<EditTransactionListDynamicRequest>(
129            (iterator,),
130            0x37862a86b057cb49,
131            fidl::encoding::DynamicFlags::empty(),
132        )
133    }
134
135    /// Removes all dynamically configured rewrite rules, leaving only any
136    /// statically configured rules.
137    pub fn r#reset_all(&self) -> Result<(), fidl::Error> {
138        self.client.send::<fidl::encoding::EmptyPayload>(
139            (),
140            0x41e518acd0864a90,
141            fidl::encoding::DynamicFlags::empty(),
142        )
143    }
144
145    /// Adds a rewrite rule with highest priority. If `rule` already exists, this
146    /// API will prioritize it over other rules.
147    ///
148    /// + request `rule` the rewrite rule to persist.
149    /// * error a zx_status value indicating failure. One of the following:
150    ///     * `ZX_ERR_INVALID_ARGS` if `url` is not a valid `fuchsia-pkg://`
151    ///      URL. See [`fuchsia-pkg URL`].
152    ///
153    /// [`fuchsia-pkg URL`]:
154    ///    https://fuchsia.dev/fuchsia-src/concepts/storage/package_url
155    pub fn r#add(
156        &self,
157        mut rule: &Rule,
158        ___deadline: zx::MonotonicInstant,
159    ) -> Result<EditTransactionAddResult, fidl::Error> {
160        let _response = self.client.send_query::<
161            EditTransactionAddRequest,
162            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
163        >(
164            (rule,),
165            0x56a2b5fe92ca5db6,
166            fidl::encoding::DynamicFlags::empty(),
167            ___deadline,
168        )?;
169        Ok(_response.map(|x| x))
170    }
171
172    /// Commits this transaction, or detect another transaction that committed
173    /// before this one.
174    ///
175    /// * error a zx_status value indicating failure. One of the following:
176    ///     * `ZX_ERR_UNAVAILABLE` if another transaction committed before this one.
177    ///     * `ZX_ERR_ACCESS_DENIED` if editing dynamic rewrite rules is permanently disabled.
178    pub fn r#commit(
179        &self,
180        ___deadline: zx::MonotonicInstant,
181    ) -> Result<EditTransactionCommitResult, fidl::Error> {
182        let _response = self.client.send_query::<
183            fidl::encoding::EmptyPayload,
184            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
185        >(
186            (),
187            0x3ca50fc9c13341fb,
188            fidl::encoding::DynamicFlags::empty(),
189            ___deadline,
190        )?;
191        Ok(_response.map(|x| x))
192    }
193}
194
195#[cfg(target_os = "fuchsia")]
196impl From<EditTransactionSynchronousProxy> for zx::Handle {
197    fn from(value: EditTransactionSynchronousProxy) -> Self {
198        value.into_channel().into()
199    }
200}
201
202#[cfg(target_os = "fuchsia")]
203impl From<fidl::Channel> for EditTransactionSynchronousProxy {
204    fn from(value: fidl::Channel) -> Self {
205        Self::new(value)
206    }
207}
208
209#[derive(Debug, Clone)]
210pub struct EditTransactionProxy {
211    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
212}
213
214impl fidl::endpoints::Proxy for EditTransactionProxy {
215    type Protocol = EditTransactionMarker;
216
217    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
218        Self::new(inner)
219    }
220
221    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
222        self.client.into_channel().map_err(|client| Self { client })
223    }
224
225    fn as_channel(&self) -> &::fidl::AsyncChannel {
226        self.client.as_channel()
227    }
228}
229
230impl EditTransactionProxy {
231    /// Create a new Proxy for fuchsia.pkg.rewrite/EditTransaction.
232    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
233        let protocol_name = <EditTransactionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
234        Self { client: fidl::client::Client::new(channel, protocol_name) }
235    }
236
237    /// Get a Stream of events from the remote end of the protocol.
238    ///
239    /// # Panics
240    ///
241    /// Panics if the event stream was already taken.
242    pub fn take_event_stream(&self) -> EditTransactionEventStream {
243        EditTransactionEventStream { event_receiver: self.client.take_event_receiver() }
244    }
245
246    /// Returns an iterator over all dynamic (editable) rewrite rules. The
247    /// iterator will reflect any changes made to the rewrite rules so far in
248    /// this transaction.
249    ///
250    /// + request `iterator` a request for an iterator.
251    pub fn r#list_dynamic(
252        &self,
253        mut iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
254    ) -> Result<(), fidl::Error> {
255        EditTransactionProxyInterface::r#list_dynamic(self, iterator)
256    }
257
258    /// Removes all dynamically configured rewrite rules, leaving only any
259    /// statically configured rules.
260    pub fn r#reset_all(&self) -> Result<(), fidl::Error> {
261        EditTransactionProxyInterface::r#reset_all(self)
262    }
263
264    /// Adds a rewrite rule with highest priority. If `rule` already exists, this
265    /// API will prioritize it over other rules.
266    ///
267    /// + request `rule` the rewrite rule to persist.
268    /// * error a zx_status value indicating failure. One of the following:
269    ///     * `ZX_ERR_INVALID_ARGS` if `url` is not a valid `fuchsia-pkg://`
270    ///      URL. See [`fuchsia-pkg URL`].
271    ///
272    /// [`fuchsia-pkg URL`]:
273    ///    https://fuchsia.dev/fuchsia-src/concepts/storage/package_url
274    pub fn r#add(
275        &self,
276        mut rule: &Rule,
277    ) -> fidl::client::QueryResponseFut<
278        EditTransactionAddResult,
279        fidl::encoding::DefaultFuchsiaResourceDialect,
280    > {
281        EditTransactionProxyInterface::r#add(self, rule)
282    }
283
284    /// Commits this transaction, or detect another transaction that committed
285    /// before this one.
286    ///
287    /// * error a zx_status value indicating failure. One of the following:
288    ///     * `ZX_ERR_UNAVAILABLE` if another transaction committed before this one.
289    ///     * `ZX_ERR_ACCESS_DENIED` if editing dynamic rewrite rules is permanently disabled.
290    pub fn r#commit(
291        &self,
292    ) -> fidl::client::QueryResponseFut<
293        EditTransactionCommitResult,
294        fidl::encoding::DefaultFuchsiaResourceDialect,
295    > {
296        EditTransactionProxyInterface::r#commit(self)
297    }
298}
299
300impl EditTransactionProxyInterface for EditTransactionProxy {
301    fn r#list_dynamic(
302        &self,
303        mut iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
304    ) -> Result<(), fidl::Error> {
305        self.client.send::<EditTransactionListDynamicRequest>(
306            (iterator,),
307            0x37862a86b057cb49,
308            fidl::encoding::DynamicFlags::empty(),
309        )
310    }
311
312    fn r#reset_all(&self) -> Result<(), fidl::Error> {
313        self.client.send::<fidl::encoding::EmptyPayload>(
314            (),
315            0x41e518acd0864a90,
316            fidl::encoding::DynamicFlags::empty(),
317        )
318    }
319
320    type AddResponseFut = fidl::client::QueryResponseFut<
321        EditTransactionAddResult,
322        fidl::encoding::DefaultFuchsiaResourceDialect,
323    >;
324    fn r#add(&self, mut rule: &Rule) -> Self::AddResponseFut {
325        fn _decode(
326            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
327        ) -> Result<EditTransactionAddResult, fidl::Error> {
328            let _response = fidl::client::decode_transaction_body::<
329                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
330                fidl::encoding::DefaultFuchsiaResourceDialect,
331                0x56a2b5fe92ca5db6,
332            >(_buf?)?;
333            Ok(_response.map(|x| x))
334        }
335        self.client.send_query_and_decode::<EditTransactionAddRequest, EditTransactionAddResult>(
336            (rule,),
337            0x56a2b5fe92ca5db6,
338            fidl::encoding::DynamicFlags::empty(),
339            _decode,
340        )
341    }
342
343    type CommitResponseFut = fidl::client::QueryResponseFut<
344        EditTransactionCommitResult,
345        fidl::encoding::DefaultFuchsiaResourceDialect,
346    >;
347    fn r#commit(&self) -> Self::CommitResponseFut {
348        fn _decode(
349            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
350        ) -> Result<EditTransactionCommitResult, fidl::Error> {
351            let _response = fidl::client::decode_transaction_body::<
352                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
353                fidl::encoding::DefaultFuchsiaResourceDialect,
354                0x3ca50fc9c13341fb,
355            >(_buf?)?;
356            Ok(_response.map(|x| x))
357        }
358        self.client
359            .send_query_and_decode::<fidl::encoding::EmptyPayload, EditTransactionCommitResult>(
360                (),
361                0x3ca50fc9c13341fb,
362                fidl::encoding::DynamicFlags::empty(),
363                _decode,
364            )
365    }
366}
367
368pub struct EditTransactionEventStream {
369    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
370}
371
372impl std::marker::Unpin for EditTransactionEventStream {}
373
374impl futures::stream::FusedStream for EditTransactionEventStream {
375    fn is_terminated(&self) -> bool {
376        self.event_receiver.is_terminated()
377    }
378}
379
380impl futures::Stream for EditTransactionEventStream {
381    type Item = Result<EditTransactionEvent, fidl::Error>;
382
383    fn poll_next(
384        mut self: std::pin::Pin<&mut Self>,
385        cx: &mut std::task::Context<'_>,
386    ) -> std::task::Poll<Option<Self::Item>> {
387        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
388            &mut self.event_receiver,
389            cx
390        )?) {
391            Some(buf) => std::task::Poll::Ready(Some(EditTransactionEvent::decode(buf))),
392            None => std::task::Poll::Ready(None),
393        }
394    }
395}
396
397#[derive(Debug)]
398pub enum EditTransactionEvent {}
399
400impl EditTransactionEvent {
401    /// Decodes a message buffer as a [`EditTransactionEvent`].
402    fn decode(
403        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
404    ) -> Result<EditTransactionEvent, fidl::Error> {
405        let (bytes, _handles) = buf.split_mut();
406        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
407        debug_assert_eq!(tx_header.tx_id, 0);
408        match tx_header.ordinal {
409            _ => Err(fidl::Error::UnknownOrdinal {
410                ordinal: tx_header.ordinal,
411                protocol_name:
412                    <EditTransactionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
413            }),
414        }
415    }
416}
417
418/// A Stream of incoming requests for fuchsia.pkg.rewrite/EditTransaction.
419pub struct EditTransactionRequestStream {
420    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
421    is_terminated: bool,
422}
423
424impl std::marker::Unpin for EditTransactionRequestStream {}
425
426impl futures::stream::FusedStream for EditTransactionRequestStream {
427    fn is_terminated(&self) -> bool {
428        self.is_terminated
429    }
430}
431
432impl fidl::endpoints::RequestStream for EditTransactionRequestStream {
433    type Protocol = EditTransactionMarker;
434    type ControlHandle = EditTransactionControlHandle;
435
436    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
437        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
438    }
439
440    fn control_handle(&self) -> Self::ControlHandle {
441        EditTransactionControlHandle { inner: self.inner.clone() }
442    }
443
444    fn into_inner(
445        self,
446    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
447    {
448        (self.inner, self.is_terminated)
449    }
450
451    fn from_inner(
452        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
453        is_terminated: bool,
454    ) -> Self {
455        Self { inner, is_terminated }
456    }
457}
458
459impl futures::Stream for EditTransactionRequestStream {
460    type Item = Result<EditTransactionRequest, fidl::Error>;
461
462    fn poll_next(
463        mut self: std::pin::Pin<&mut Self>,
464        cx: &mut std::task::Context<'_>,
465    ) -> std::task::Poll<Option<Self::Item>> {
466        let this = &mut *self;
467        if this.inner.check_shutdown(cx) {
468            this.is_terminated = true;
469            return std::task::Poll::Ready(None);
470        }
471        if this.is_terminated {
472            panic!("polled EditTransactionRequestStream after completion");
473        }
474        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
475            |bytes, handles| {
476                match this.inner.channel().read_etc(cx, bytes, handles) {
477                    std::task::Poll::Ready(Ok(())) => {}
478                    std::task::Poll::Pending => return std::task::Poll::Pending,
479                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
480                        this.is_terminated = true;
481                        return std::task::Poll::Ready(None);
482                    }
483                    std::task::Poll::Ready(Err(e)) => {
484                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
485                            e.into(),
486                        ))))
487                    }
488                }
489
490                // A message has been received from the channel
491                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
492
493                std::task::Poll::Ready(Some(match header.ordinal {
494                    0x37862a86b057cb49 => {
495                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
496                        let mut req = fidl::new_empty!(
497                            EditTransactionListDynamicRequest,
498                            fidl::encoding::DefaultFuchsiaResourceDialect
499                        );
500                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<EditTransactionListDynamicRequest>(&header, _body_bytes, handles, &mut req)?;
501                        let control_handle =
502                            EditTransactionControlHandle { inner: this.inner.clone() };
503                        Ok(EditTransactionRequest::ListDynamic {
504                            iterator: req.iterator,
505
506                            control_handle,
507                        })
508                    }
509                    0x41e518acd0864a90 => {
510                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
511                        let mut req = fidl::new_empty!(
512                            fidl::encoding::EmptyPayload,
513                            fidl::encoding::DefaultFuchsiaResourceDialect
514                        );
515                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
516                        let control_handle =
517                            EditTransactionControlHandle { inner: this.inner.clone() };
518                        Ok(EditTransactionRequest::ResetAll { control_handle })
519                    }
520                    0x56a2b5fe92ca5db6 => {
521                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
522                        let mut req = fidl::new_empty!(
523                            EditTransactionAddRequest,
524                            fidl::encoding::DefaultFuchsiaResourceDialect
525                        );
526                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<EditTransactionAddRequest>(&header, _body_bytes, handles, &mut req)?;
527                        let control_handle =
528                            EditTransactionControlHandle { inner: this.inner.clone() };
529                        Ok(EditTransactionRequest::Add {
530                            rule: req.rule,
531
532                            responder: EditTransactionAddResponder {
533                                control_handle: std::mem::ManuallyDrop::new(control_handle),
534                                tx_id: header.tx_id,
535                            },
536                        })
537                    }
538                    0x3ca50fc9c13341fb => {
539                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
540                        let mut req = fidl::new_empty!(
541                            fidl::encoding::EmptyPayload,
542                            fidl::encoding::DefaultFuchsiaResourceDialect
543                        );
544                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
545                        let control_handle =
546                            EditTransactionControlHandle { inner: this.inner.clone() };
547                        Ok(EditTransactionRequest::Commit {
548                            responder: EditTransactionCommitResponder {
549                                control_handle: std::mem::ManuallyDrop::new(control_handle),
550                                tx_id: header.tx_id,
551                            },
552                        })
553                    }
554                    _ => Err(fidl::Error::UnknownOrdinal {
555                        ordinal: header.ordinal,
556                        protocol_name:
557                            <EditTransactionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
558                    }),
559                }))
560            },
561        )
562    }
563}
564
565/// A unit of editing for rewrite rules.
566#[derive(Debug)]
567pub enum EditTransactionRequest {
568    /// Returns an iterator over all dynamic (editable) rewrite rules. The
569    /// iterator will reflect any changes made to the rewrite rules so far in
570    /// this transaction.
571    ///
572    /// + request `iterator` a request for an iterator.
573    ListDynamic {
574        iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
575        control_handle: EditTransactionControlHandle,
576    },
577    /// Removes all dynamically configured rewrite rules, leaving only any
578    /// statically configured rules.
579    ResetAll { control_handle: EditTransactionControlHandle },
580    /// Adds a rewrite rule with highest priority. If `rule` already exists, this
581    /// API will prioritize it over other rules.
582    ///
583    /// + request `rule` the rewrite rule to persist.
584    /// * error a zx_status value indicating failure. One of the following:
585    ///     * `ZX_ERR_INVALID_ARGS` if `url` is not a valid `fuchsia-pkg://`
586    ///      URL. See [`fuchsia-pkg URL`].
587    ///
588    /// [`fuchsia-pkg URL`]:
589    ///    https://fuchsia.dev/fuchsia-src/concepts/storage/package_url
590    Add { rule: Rule, responder: EditTransactionAddResponder },
591    /// Commits this transaction, or detect another transaction that committed
592    /// before this one.
593    ///
594    /// * error a zx_status value indicating failure. One of the following:
595    ///     * `ZX_ERR_UNAVAILABLE` if another transaction committed before this one.
596    ///     * `ZX_ERR_ACCESS_DENIED` if editing dynamic rewrite rules is permanently disabled.
597    Commit { responder: EditTransactionCommitResponder },
598}
599
600impl EditTransactionRequest {
601    #[allow(irrefutable_let_patterns)]
602    pub fn into_list_dynamic(
603        self,
604    ) -> Option<(fidl::endpoints::ServerEnd<RuleIteratorMarker>, EditTransactionControlHandle)>
605    {
606        if let EditTransactionRequest::ListDynamic { iterator, control_handle } = self {
607            Some((iterator, control_handle))
608        } else {
609            None
610        }
611    }
612
613    #[allow(irrefutable_let_patterns)]
614    pub fn into_reset_all(self) -> Option<(EditTransactionControlHandle)> {
615        if let EditTransactionRequest::ResetAll { control_handle } = self {
616            Some((control_handle))
617        } else {
618            None
619        }
620    }
621
622    #[allow(irrefutable_let_patterns)]
623    pub fn into_add(self) -> Option<(Rule, EditTransactionAddResponder)> {
624        if let EditTransactionRequest::Add { rule, responder } = self {
625            Some((rule, responder))
626        } else {
627            None
628        }
629    }
630
631    #[allow(irrefutable_let_patterns)]
632    pub fn into_commit(self) -> Option<(EditTransactionCommitResponder)> {
633        if let EditTransactionRequest::Commit { responder } = self {
634            Some((responder))
635        } else {
636            None
637        }
638    }
639
640    /// Name of the method defined in FIDL
641    pub fn method_name(&self) -> &'static str {
642        match *self {
643            EditTransactionRequest::ListDynamic { .. } => "list_dynamic",
644            EditTransactionRequest::ResetAll { .. } => "reset_all",
645            EditTransactionRequest::Add { .. } => "add",
646            EditTransactionRequest::Commit { .. } => "commit",
647        }
648    }
649}
650
651#[derive(Debug, Clone)]
652pub struct EditTransactionControlHandle {
653    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
654}
655
656impl fidl::endpoints::ControlHandle for EditTransactionControlHandle {
657    fn shutdown(&self) {
658        self.inner.shutdown()
659    }
660    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
661        self.inner.shutdown_with_epitaph(status)
662    }
663
664    fn is_closed(&self) -> bool {
665        self.inner.channel().is_closed()
666    }
667    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
668        self.inner.channel().on_closed()
669    }
670
671    #[cfg(target_os = "fuchsia")]
672    fn signal_peer(
673        &self,
674        clear_mask: zx::Signals,
675        set_mask: zx::Signals,
676    ) -> Result<(), zx_status::Status> {
677        use fidl::Peered;
678        self.inner.channel().signal_peer(clear_mask, set_mask)
679    }
680}
681
682impl EditTransactionControlHandle {}
683
684#[must_use = "FIDL methods require a response to be sent"]
685#[derive(Debug)]
686pub struct EditTransactionAddResponder {
687    control_handle: std::mem::ManuallyDrop<EditTransactionControlHandle>,
688    tx_id: u32,
689}
690
691/// Set the the channel to be shutdown (see [`EditTransactionControlHandle::shutdown`])
692/// if the responder is dropped without sending a response, so that the client
693/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
694impl std::ops::Drop for EditTransactionAddResponder {
695    fn drop(&mut self) {
696        self.control_handle.shutdown();
697        // Safety: drops once, never accessed again
698        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
699    }
700}
701
702impl fidl::endpoints::Responder for EditTransactionAddResponder {
703    type ControlHandle = EditTransactionControlHandle;
704
705    fn control_handle(&self) -> &EditTransactionControlHandle {
706        &self.control_handle
707    }
708
709    fn drop_without_shutdown(mut self) {
710        // Safety: drops once, never accessed again due to mem::forget
711        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
712        // Prevent Drop from running (which would shut down the channel)
713        std::mem::forget(self);
714    }
715}
716
717impl EditTransactionAddResponder {
718    /// Sends a response to the FIDL transaction.
719    ///
720    /// Sets the channel to shutdown if an error occurs.
721    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
722        let _result = self.send_raw(result);
723        if _result.is_err() {
724            self.control_handle.shutdown();
725        }
726        self.drop_without_shutdown();
727        _result
728    }
729
730    /// Similar to "send" but does not shutdown the channel if an error occurs.
731    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
732        let _result = self.send_raw(result);
733        self.drop_without_shutdown();
734        _result
735    }
736
737    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
738        self.control_handle
739            .inner
740            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
741                result,
742                self.tx_id,
743                0x56a2b5fe92ca5db6,
744                fidl::encoding::DynamicFlags::empty(),
745            )
746    }
747}
748
749#[must_use = "FIDL methods require a response to be sent"]
750#[derive(Debug)]
751pub struct EditTransactionCommitResponder {
752    control_handle: std::mem::ManuallyDrop<EditTransactionControlHandle>,
753    tx_id: u32,
754}
755
756/// Set the the channel to be shutdown (see [`EditTransactionControlHandle::shutdown`])
757/// if the responder is dropped without sending a response, so that the client
758/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
759impl std::ops::Drop for EditTransactionCommitResponder {
760    fn drop(&mut self) {
761        self.control_handle.shutdown();
762        // Safety: drops once, never accessed again
763        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
764    }
765}
766
767impl fidl::endpoints::Responder for EditTransactionCommitResponder {
768    type ControlHandle = EditTransactionControlHandle;
769
770    fn control_handle(&self) -> &EditTransactionControlHandle {
771        &self.control_handle
772    }
773
774    fn drop_without_shutdown(mut self) {
775        // Safety: drops once, never accessed again due to mem::forget
776        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
777        // Prevent Drop from running (which would shut down the channel)
778        std::mem::forget(self);
779    }
780}
781
782impl EditTransactionCommitResponder {
783    /// Sends a response to the FIDL transaction.
784    ///
785    /// Sets the channel to shutdown if an error occurs.
786    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
787        let _result = self.send_raw(result);
788        if _result.is_err() {
789            self.control_handle.shutdown();
790        }
791        self.drop_without_shutdown();
792        _result
793    }
794
795    /// Similar to "send" but does not shutdown the channel if an error occurs.
796    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
797        let _result = self.send_raw(result);
798        self.drop_without_shutdown();
799        _result
800    }
801
802    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
803        self.control_handle
804            .inner
805            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
806                result,
807                self.tx_id,
808                0x3ca50fc9c13341fb,
809                fidl::encoding::DynamicFlags::empty(),
810            )
811    }
812}
813
814#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
815pub struct EngineMarker;
816
817impl fidl::endpoints::ProtocolMarker for EngineMarker {
818    type Proxy = EngineProxy;
819    type RequestStream = EngineRequestStream;
820    #[cfg(target_os = "fuchsia")]
821    type SynchronousProxy = EngineSynchronousProxy;
822
823    const DEBUG_NAME: &'static str = "fuchsia.pkg.rewrite.Engine";
824}
825impl fidl::endpoints::DiscoverableProtocolMarker for EngineMarker {}
826pub type EngineTestApplyResult = Result<String, i32>;
827
828pub trait EngineProxyInterface: Send + Sync {
829    fn r#start_edit_transaction(
830        &self,
831        transaction: fidl::endpoints::ServerEnd<EditTransactionMarker>,
832    ) -> Result<(), fidl::Error>;
833    fn r#list(
834        &self,
835        iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
836    ) -> Result<(), fidl::Error>;
837    fn r#list_static(
838        &self,
839        iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
840    ) -> Result<(), fidl::Error>;
841    type TestApplyResponseFut: std::future::Future<Output = Result<EngineTestApplyResult, fidl::Error>>
842        + Send;
843    fn r#test_apply(&self, url: &str) -> Self::TestApplyResponseFut;
844}
845#[derive(Debug)]
846#[cfg(target_os = "fuchsia")]
847pub struct EngineSynchronousProxy {
848    client: fidl::client::sync::Client,
849}
850
851#[cfg(target_os = "fuchsia")]
852impl fidl::endpoints::SynchronousProxy for EngineSynchronousProxy {
853    type Proxy = EngineProxy;
854    type Protocol = EngineMarker;
855
856    fn from_channel(inner: fidl::Channel) -> Self {
857        Self::new(inner)
858    }
859
860    fn into_channel(self) -> fidl::Channel {
861        self.client.into_channel()
862    }
863
864    fn as_channel(&self) -> &fidl::Channel {
865        self.client.as_channel()
866    }
867}
868
869#[cfg(target_os = "fuchsia")]
870impl EngineSynchronousProxy {
871    pub fn new(channel: fidl::Channel) -> Self {
872        let protocol_name = <EngineMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
873        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
874    }
875
876    pub fn into_channel(self) -> fidl::Channel {
877        self.client.into_channel()
878    }
879
880    /// Waits until an event arrives and returns it. It is safe for other
881    /// threads to make concurrent requests while waiting for an event.
882    pub fn wait_for_event(
883        &self,
884        deadline: zx::MonotonicInstant,
885    ) -> Result<EngineEvent, fidl::Error> {
886        EngineEvent::decode(self.client.wait_for_event(deadline)?)
887    }
888
889    /// Begins a rule edit transaction.
890    ///
891    /// + request `transaction` a request for an [`EditTransaction`].
892    pub fn r#start_edit_transaction(
893        &self,
894        mut transaction: fidl::endpoints::ServerEnd<EditTransactionMarker>,
895    ) -> Result<(), fidl::Error> {
896        self.client.send::<EngineStartEditTransactionRequest>(
897            (transaction,),
898            0x6f649b7dbbc904fb,
899            fidl::encoding::DynamicFlags::empty(),
900        )
901    }
902
903    /// Returns an iterator over all rewrite rules.
904    ///
905    /// + request `iterator` a request for an iterator.
906    pub fn r#list(
907        &self,
908        mut iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
909    ) -> Result<(), fidl::Error> {
910        self.client.send::<EngineListRequest>(
911            (iterator,),
912            0xccbc8b5cb10ad14,
913            fidl::encoding::DynamicFlags::empty(),
914        )
915    }
916
917    /// Returns an iterator over all static (immutable) rewrite rules. These
918    /// rules are handled as lower priority than dynamic rules and cannot be
919    /// modified (although they can be overridden) by [`EditTransaction`]s.
920    ///
921    /// + request `iterator` a request for an iterator.
922    pub fn r#list_static(
923        &self,
924        mut iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
925    ) -> Result<(), fidl::Error> {
926        self.client.send::<EngineListStaticRequest>(
927            (iterator,),
928            0x5416f92d0bac1b30,
929            fidl::encoding::DynamicFlags::empty(),
930        )
931    }
932
933    /// Rewrites the given `url` with the current rewrite rule set, returning the
934    /// `rewritten` url.  If no rules match or a rule matches but performs an
935    /// identity transformation, this API returns `url` unchanged.
936    ///
937    /// This API is intended only for reflecting on rule side effects. Using
938    /// this API to pre-apply the rules, then passing the result to
939    /// [`fuchsia.pkg/PackageResolver.Resolve`] would apply the rules twice.
940    ///
941    /// + request `url` the url to rewrite.
942    /// - response `rewritten` the rewritten url.
943    /// * error a zx_status value indicating failure. One of the following:
944    ///     * `ZX_ERR_INVALID_ARGS` if `url` is not a valid `fuchsia-pkg://`
945    ///       URL. See [`fuchsia-pkg URL`].
946    ///
947    /// [`fuchsia-pkg URL`]:
948    ///    https://fuchsia.dev/fuchsia-src/concepts/storage/package_url
949    pub fn r#test_apply(
950        &self,
951        mut url: &str,
952        ___deadline: zx::MonotonicInstant,
953    ) -> Result<EngineTestApplyResult, fidl::Error> {
954        let _response = self.client.send_query::<
955            EngineTestApplyRequest,
956            fidl::encoding::ResultType<EngineTestApplyResponse, i32>,
957        >(
958            (url,),
959            0xc8826a2b36fca39,
960            fidl::encoding::DynamicFlags::empty(),
961            ___deadline,
962        )?;
963        Ok(_response.map(|x| x.rewritten))
964    }
965}
966
967#[cfg(target_os = "fuchsia")]
968impl From<EngineSynchronousProxy> for zx::Handle {
969    fn from(value: EngineSynchronousProxy) -> Self {
970        value.into_channel().into()
971    }
972}
973
974#[cfg(target_os = "fuchsia")]
975impl From<fidl::Channel> for EngineSynchronousProxy {
976    fn from(value: fidl::Channel) -> Self {
977        Self::new(value)
978    }
979}
980
981#[derive(Debug, Clone)]
982pub struct EngineProxy {
983    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
984}
985
986impl fidl::endpoints::Proxy for EngineProxy {
987    type Protocol = EngineMarker;
988
989    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
990        Self::new(inner)
991    }
992
993    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
994        self.client.into_channel().map_err(|client| Self { client })
995    }
996
997    fn as_channel(&self) -> &::fidl::AsyncChannel {
998        self.client.as_channel()
999    }
1000}
1001
1002impl EngineProxy {
1003    /// Create a new Proxy for fuchsia.pkg.rewrite/Engine.
1004    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1005        let protocol_name = <EngineMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1006        Self { client: fidl::client::Client::new(channel, protocol_name) }
1007    }
1008
1009    /// Get a Stream of events from the remote end of the protocol.
1010    ///
1011    /// # Panics
1012    ///
1013    /// Panics if the event stream was already taken.
1014    pub fn take_event_stream(&self) -> EngineEventStream {
1015        EngineEventStream { event_receiver: self.client.take_event_receiver() }
1016    }
1017
1018    /// Begins a rule edit transaction.
1019    ///
1020    /// + request `transaction` a request for an [`EditTransaction`].
1021    pub fn r#start_edit_transaction(
1022        &self,
1023        mut transaction: fidl::endpoints::ServerEnd<EditTransactionMarker>,
1024    ) -> Result<(), fidl::Error> {
1025        EngineProxyInterface::r#start_edit_transaction(self, transaction)
1026    }
1027
1028    /// Returns an iterator over all rewrite rules.
1029    ///
1030    /// + request `iterator` a request for an iterator.
1031    pub fn r#list(
1032        &self,
1033        mut iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
1034    ) -> Result<(), fidl::Error> {
1035        EngineProxyInterface::r#list(self, iterator)
1036    }
1037
1038    /// Returns an iterator over all static (immutable) rewrite rules. These
1039    /// rules are handled as lower priority than dynamic rules and cannot be
1040    /// modified (although they can be overridden) by [`EditTransaction`]s.
1041    ///
1042    /// + request `iterator` a request for an iterator.
1043    pub fn r#list_static(
1044        &self,
1045        mut iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
1046    ) -> Result<(), fidl::Error> {
1047        EngineProxyInterface::r#list_static(self, iterator)
1048    }
1049
1050    /// Rewrites the given `url` with the current rewrite rule set, returning the
1051    /// `rewritten` url.  If no rules match or a rule matches but performs an
1052    /// identity transformation, this API returns `url` unchanged.
1053    ///
1054    /// This API is intended only for reflecting on rule side effects. Using
1055    /// this API to pre-apply the rules, then passing the result to
1056    /// [`fuchsia.pkg/PackageResolver.Resolve`] would apply the rules twice.
1057    ///
1058    /// + request `url` the url to rewrite.
1059    /// - response `rewritten` the rewritten url.
1060    /// * error a zx_status value indicating failure. One of the following:
1061    ///     * `ZX_ERR_INVALID_ARGS` if `url` is not a valid `fuchsia-pkg://`
1062    ///       URL. See [`fuchsia-pkg URL`].
1063    ///
1064    /// [`fuchsia-pkg URL`]:
1065    ///    https://fuchsia.dev/fuchsia-src/concepts/storage/package_url
1066    pub fn r#test_apply(
1067        &self,
1068        mut url: &str,
1069    ) -> fidl::client::QueryResponseFut<
1070        EngineTestApplyResult,
1071        fidl::encoding::DefaultFuchsiaResourceDialect,
1072    > {
1073        EngineProxyInterface::r#test_apply(self, url)
1074    }
1075}
1076
1077impl EngineProxyInterface for EngineProxy {
1078    fn r#start_edit_transaction(
1079        &self,
1080        mut transaction: fidl::endpoints::ServerEnd<EditTransactionMarker>,
1081    ) -> Result<(), fidl::Error> {
1082        self.client.send::<EngineStartEditTransactionRequest>(
1083            (transaction,),
1084            0x6f649b7dbbc904fb,
1085            fidl::encoding::DynamicFlags::empty(),
1086        )
1087    }
1088
1089    fn r#list(
1090        &self,
1091        mut iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
1092    ) -> Result<(), fidl::Error> {
1093        self.client.send::<EngineListRequest>(
1094            (iterator,),
1095            0xccbc8b5cb10ad14,
1096            fidl::encoding::DynamicFlags::empty(),
1097        )
1098    }
1099
1100    fn r#list_static(
1101        &self,
1102        mut iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
1103    ) -> Result<(), fidl::Error> {
1104        self.client.send::<EngineListStaticRequest>(
1105            (iterator,),
1106            0x5416f92d0bac1b30,
1107            fidl::encoding::DynamicFlags::empty(),
1108        )
1109    }
1110
1111    type TestApplyResponseFut = fidl::client::QueryResponseFut<
1112        EngineTestApplyResult,
1113        fidl::encoding::DefaultFuchsiaResourceDialect,
1114    >;
1115    fn r#test_apply(&self, mut url: &str) -> Self::TestApplyResponseFut {
1116        fn _decode(
1117            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1118        ) -> Result<EngineTestApplyResult, fidl::Error> {
1119            let _response = fidl::client::decode_transaction_body::<
1120                fidl::encoding::ResultType<EngineTestApplyResponse, i32>,
1121                fidl::encoding::DefaultFuchsiaResourceDialect,
1122                0xc8826a2b36fca39,
1123            >(_buf?)?;
1124            Ok(_response.map(|x| x.rewritten))
1125        }
1126        self.client.send_query_and_decode::<EngineTestApplyRequest, EngineTestApplyResult>(
1127            (url,),
1128            0xc8826a2b36fca39,
1129            fidl::encoding::DynamicFlags::empty(),
1130            _decode,
1131        )
1132    }
1133}
1134
1135pub struct EngineEventStream {
1136    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1137}
1138
1139impl std::marker::Unpin for EngineEventStream {}
1140
1141impl futures::stream::FusedStream for EngineEventStream {
1142    fn is_terminated(&self) -> bool {
1143        self.event_receiver.is_terminated()
1144    }
1145}
1146
1147impl futures::Stream for EngineEventStream {
1148    type Item = Result<EngineEvent, fidl::Error>;
1149
1150    fn poll_next(
1151        mut self: std::pin::Pin<&mut Self>,
1152        cx: &mut std::task::Context<'_>,
1153    ) -> std::task::Poll<Option<Self::Item>> {
1154        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1155            &mut self.event_receiver,
1156            cx
1157        )?) {
1158            Some(buf) => std::task::Poll::Ready(Some(EngineEvent::decode(buf))),
1159            None => std::task::Poll::Ready(None),
1160        }
1161    }
1162}
1163
1164#[derive(Debug)]
1165pub enum EngineEvent {}
1166
1167impl EngineEvent {
1168    /// Decodes a message buffer as a [`EngineEvent`].
1169    fn decode(
1170        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1171    ) -> Result<EngineEvent, fidl::Error> {
1172        let (bytes, _handles) = buf.split_mut();
1173        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1174        debug_assert_eq!(tx_header.tx_id, 0);
1175        match tx_header.ordinal {
1176            _ => Err(fidl::Error::UnknownOrdinal {
1177                ordinal: tx_header.ordinal,
1178                protocol_name: <EngineMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1179            }),
1180        }
1181    }
1182}
1183
1184/// A Stream of incoming requests for fuchsia.pkg.rewrite/Engine.
1185pub struct EngineRequestStream {
1186    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1187    is_terminated: bool,
1188}
1189
1190impl std::marker::Unpin for EngineRequestStream {}
1191
1192impl futures::stream::FusedStream for EngineRequestStream {
1193    fn is_terminated(&self) -> bool {
1194        self.is_terminated
1195    }
1196}
1197
1198impl fidl::endpoints::RequestStream for EngineRequestStream {
1199    type Protocol = EngineMarker;
1200    type ControlHandle = EngineControlHandle;
1201
1202    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1203        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1204    }
1205
1206    fn control_handle(&self) -> Self::ControlHandle {
1207        EngineControlHandle { inner: self.inner.clone() }
1208    }
1209
1210    fn into_inner(
1211        self,
1212    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1213    {
1214        (self.inner, self.is_terminated)
1215    }
1216
1217    fn from_inner(
1218        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1219        is_terminated: bool,
1220    ) -> Self {
1221        Self { inner, is_terminated }
1222    }
1223}
1224
1225impl futures::Stream for EngineRequestStream {
1226    type Item = Result<EngineRequest, fidl::Error>;
1227
1228    fn poll_next(
1229        mut self: std::pin::Pin<&mut Self>,
1230        cx: &mut std::task::Context<'_>,
1231    ) -> std::task::Poll<Option<Self::Item>> {
1232        let this = &mut *self;
1233        if this.inner.check_shutdown(cx) {
1234            this.is_terminated = true;
1235            return std::task::Poll::Ready(None);
1236        }
1237        if this.is_terminated {
1238            panic!("polled EngineRequestStream after completion");
1239        }
1240        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1241            |bytes, handles| {
1242                match this.inner.channel().read_etc(cx, bytes, handles) {
1243                    std::task::Poll::Ready(Ok(())) => {}
1244                    std::task::Poll::Pending => return std::task::Poll::Pending,
1245                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1246                        this.is_terminated = true;
1247                        return std::task::Poll::Ready(None);
1248                    }
1249                    std::task::Poll::Ready(Err(e)) => {
1250                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1251                            e.into(),
1252                        ))))
1253                    }
1254                }
1255
1256                // A message has been received from the channel
1257                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1258
1259                std::task::Poll::Ready(Some(match header.ordinal {
1260                    0x6f649b7dbbc904fb => {
1261                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1262                        let mut req = fidl::new_empty!(
1263                            EngineStartEditTransactionRequest,
1264                            fidl::encoding::DefaultFuchsiaResourceDialect
1265                        );
1266                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<EngineStartEditTransactionRequest>(&header, _body_bytes, handles, &mut req)?;
1267                        let control_handle = EngineControlHandle { inner: this.inner.clone() };
1268                        Ok(EngineRequest::StartEditTransaction {
1269                            transaction: req.transaction,
1270
1271                            control_handle,
1272                        })
1273                    }
1274                    0xccbc8b5cb10ad14 => {
1275                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1276                        let mut req = fidl::new_empty!(
1277                            EngineListRequest,
1278                            fidl::encoding::DefaultFuchsiaResourceDialect
1279                        );
1280                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<EngineListRequest>(&header, _body_bytes, handles, &mut req)?;
1281                        let control_handle = EngineControlHandle { inner: this.inner.clone() };
1282                        Ok(EngineRequest::List { iterator: req.iterator, control_handle })
1283                    }
1284                    0x5416f92d0bac1b30 => {
1285                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1286                        let mut req = fidl::new_empty!(
1287                            EngineListStaticRequest,
1288                            fidl::encoding::DefaultFuchsiaResourceDialect
1289                        );
1290                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<EngineListStaticRequest>(&header, _body_bytes, handles, &mut req)?;
1291                        let control_handle = EngineControlHandle { inner: this.inner.clone() };
1292                        Ok(EngineRequest::ListStatic { iterator: req.iterator, control_handle })
1293                    }
1294                    0xc8826a2b36fca39 => {
1295                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1296                        let mut req = fidl::new_empty!(
1297                            EngineTestApplyRequest,
1298                            fidl::encoding::DefaultFuchsiaResourceDialect
1299                        );
1300                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<EngineTestApplyRequest>(&header, _body_bytes, handles, &mut req)?;
1301                        let control_handle = EngineControlHandle { inner: this.inner.clone() };
1302                        Ok(EngineRequest::TestApply {
1303                            url: req.url,
1304
1305                            responder: EngineTestApplyResponder {
1306                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1307                                tx_id: header.tx_id,
1308                            },
1309                        })
1310                    }
1311                    _ => Err(fidl::Error::UnknownOrdinal {
1312                        ordinal: header.ordinal,
1313                        protocol_name:
1314                            <EngineMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1315                    }),
1316                }))
1317            },
1318        )
1319    }
1320}
1321
1322/// This manages fuchsia-pkg:// rewrite rules.
1323///
1324/// When a package resolver is asked to resolve a fuchsia-pkg URL, it must first
1325/// iterate through its sequence of rewrite rules (given by [`List`]). The
1326/// rewrite engine will rewrite the given URL with the first rule that:
1327/// * matches the given URL
1328/// * produces a valid URL when applied to the given URL
1329///
1330/// If no rules match, the URL is resolved as-is.
1331///
1332/// This is intended to be implemented by package resolver components,
1333/// and used by repository administration tools.
1334#[derive(Debug)]
1335pub enum EngineRequest {
1336    /// Begins a rule edit transaction.
1337    ///
1338    /// + request `transaction` a request for an [`EditTransaction`].
1339    StartEditTransaction {
1340        transaction: fidl::endpoints::ServerEnd<EditTransactionMarker>,
1341        control_handle: EngineControlHandle,
1342    },
1343    /// Returns an iterator over all rewrite rules.
1344    ///
1345    /// + request `iterator` a request for an iterator.
1346    List {
1347        iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
1348        control_handle: EngineControlHandle,
1349    },
1350    /// Returns an iterator over all static (immutable) rewrite rules. These
1351    /// rules are handled as lower priority than dynamic rules and cannot be
1352    /// modified (although they can be overridden) by [`EditTransaction`]s.
1353    ///
1354    /// + request `iterator` a request for an iterator.
1355    ListStatic {
1356        iterator: fidl::endpoints::ServerEnd<RuleIteratorMarker>,
1357        control_handle: EngineControlHandle,
1358    },
1359    /// Rewrites the given `url` with the current rewrite rule set, returning the
1360    /// `rewritten` url.  If no rules match or a rule matches but performs an
1361    /// identity transformation, this API returns `url` unchanged.
1362    ///
1363    /// This API is intended only for reflecting on rule side effects. Using
1364    /// this API to pre-apply the rules, then passing the result to
1365    /// [`fuchsia.pkg/PackageResolver.Resolve`] would apply the rules twice.
1366    ///
1367    /// + request `url` the url to rewrite.
1368    /// - response `rewritten` the rewritten url.
1369    /// * error a zx_status value indicating failure. One of the following:
1370    ///     * `ZX_ERR_INVALID_ARGS` if `url` is not a valid `fuchsia-pkg://`
1371    ///       URL. See [`fuchsia-pkg URL`].
1372    ///
1373    /// [`fuchsia-pkg URL`]:
1374    ///    https://fuchsia.dev/fuchsia-src/concepts/storage/package_url
1375    TestApply { url: String, responder: EngineTestApplyResponder },
1376}
1377
1378impl EngineRequest {
1379    #[allow(irrefutable_let_patterns)]
1380    pub fn into_start_edit_transaction(
1381        self,
1382    ) -> Option<(fidl::endpoints::ServerEnd<EditTransactionMarker>, EngineControlHandle)> {
1383        if let EngineRequest::StartEditTransaction { transaction, control_handle } = self {
1384            Some((transaction, control_handle))
1385        } else {
1386            None
1387        }
1388    }
1389
1390    #[allow(irrefutable_let_patterns)]
1391    pub fn into_list(
1392        self,
1393    ) -> Option<(fidl::endpoints::ServerEnd<RuleIteratorMarker>, EngineControlHandle)> {
1394        if let EngineRequest::List { iterator, control_handle } = self {
1395            Some((iterator, control_handle))
1396        } else {
1397            None
1398        }
1399    }
1400
1401    #[allow(irrefutable_let_patterns)]
1402    pub fn into_list_static(
1403        self,
1404    ) -> Option<(fidl::endpoints::ServerEnd<RuleIteratorMarker>, EngineControlHandle)> {
1405        if let EngineRequest::ListStatic { iterator, control_handle } = self {
1406            Some((iterator, control_handle))
1407        } else {
1408            None
1409        }
1410    }
1411
1412    #[allow(irrefutable_let_patterns)]
1413    pub fn into_test_apply(self) -> Option<(String, EngineTestApplyResponder)> {
1414        if let EngineRequest::TestApply { url, responder } = self {
1415            Some((url, responder))
1416        } else {
1417            None
1418        }
1419    }
1420
1421    /// Name of the method defined in FIDL
1422    pub fn method_name(&self) -> &'static str {
1423        match *self {
1424            EngineRequest::StartEditTransaction { .. } => "start_edit_transaction",
1425            EngineRequest::List { .. } => "list",
1426            EngineRequest::ListStatic { .. } => "list_static",
1427            EngineRequest::TestApply { .. } => "test_apply",
1428        }
1429    }
1430}
1431
1432#[derive(Debug, Clone)]
1433pub struct EngineControlHandle {
1434    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1435}
1436
1437impl fidl::endpoints::ControlHandle for EngineControlHandle {
1438    fn shutdown(&self) {
1439        self.inner.shutdown()
1440    }
1441    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1442        self.inner.shutdown_with_epitaph(status)
1443    }
1444
1445    fn is_closed(&self) -> bool {
1446        self.inner.channel().is_closed()
1447    }
1448    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1449        self.inner.channel().on_closed()
1450    }
1451
1452    #[cfg(target_os = "fuchsia")]
1453    fn signal_peer(
1454        &self,
1455        clear_mask: zx::Signals,
1456        set_mask: zx::Signals,
1457    ) -> Result<(), zx_status::Status> {
1458        use fidl::Peered;
1459        self.inner.channel().signal_peer(clear_mask, set_mask)
1460    }
1461}
1462
1463impl EngineControlHandle {}
1464
1465#[must_use = "FIDL methods require a response to be sent"]
1466#[derive(Debug)]
1467pub struct EngineTestApplyResponder {
1468    control_handle: std::mem::ManuallyDrop<EngineControlHandle>,
1469    tx_id: u32,
1470}
1471
1472/// Set the the channel to be shutdown (see [`EngineControlHandle::shutdown`])
1473/// if the responder is dropped without sending a response, so that the client
1474/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1475impl std::ops::Drop for EngineTestApplyResponder {
1476    fn drop(&mut self) {
1477        self.control_handle.shutdown();
1478        // Safety: drops once, never accessed again
1479        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1480    }
1481}
1482
1483impl fidl::endpoints::Responder for EngineTestApplyResponder {
1484    type ControlHandle = EngineControlHandle;
1485
1486    fn control_handle(&self) -> &EngineControlHandle {
1487        &self.control_handle
1488    }
1489
1490    fn drop_without_shutdown(mut self) {
1491        // Safety: drops once, never accessed again due to mem::forget
1492        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1493        // Prevent Drop from running (which would shut down the channel)
1494        std::mem::forget(self);
1495    }
1496}
1497
1498impl EngineTestApplyResponder {
1499    /// Sends a response to the FIDL transaction.
1500    ///
1501    /// Sets the channel to shutdown if an error occurs.
1502    pub fn send(self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
1503        let _result = self.send_raw(result);
1504        if _result.is_err() {
1505            self.control_handle.shutdown();
1506        }
1507        self.drop_without_shutdown();
1508        _result
1509    }
1510
1511    /// Similar to "send" but does not shutdown the channel if an error occurs.
1512    pub fn send_no_shutdown_on_err(self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
1513        let _result = self.send_raw(result);
1514        self.drop_without_shutdown();
1515        _result
1516    }
1517
1518    fn send_raw(&self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
1519        self.control_handle.inner.send::<fidl::encoding::ResultType<EngineTestApplyResponse, i32>>(
1520            result.map(|rewritten| (rewritten,)),
1521            self.tx_id,
1522            0xc8826a2b36fca39,
1523            fidl::encoding::DynamicFlags::empty(),
1524        )
1525    }
1526}
1527
1528#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1529pub struct RuleIteratorMarker;
1530
1531impl fidl::endpoints::ProtocolMarker for RuleIteratorMarker {
1532    type Proxy = RuleIteratorProxy;
1533    type RequestStream = RuleIteratorRequestStream;
1534    #[cfg(target_os = "fuchsia")]
1535    type SynchronousProxy = RuleIteratorSynchronousProxy;
1536
1537    const DEBUG_NAME: &'static str = "(anonymous) RuleIterator";
1538}
1539
1540pub trait RuleIteratorProxyInterface: Send + Sync {
1541    type NextResponseFut: std::future::Future<Output = Result<Vec<Rule>, fidl::Error>> + Send;
1542    fn r#next(&self) -> Self::NextResponseFut;
1543}
1544#[derive(Debug)]
1545#[cfg(target_os = "fuchsia")]
1546pub struct RuleIteratorSynchronousProxy {
1547    client: fidl::client::sync::Client,
1548}
1549
1550#[cfg(target_os = "fuchsia")]
1551impl fidl::endpoints::SynchronousProxy for RuleIteratorSynchronousProxy {
1552    type Proxy = RuleIteratorProxy;
1553    type Protocol = RuleIteratorMarker;
1554
1555    fn from_channel(inner: fidl::Channel) -> Self {
1556        Self::new(inner)
1557    }
1558
1559    fn into_channel(self) -> fidl::Channel {
1560        self.client.into_channel()
1561    }
1562
1563    fn as_channel(&self) -> &fidl::Channel {
1564        self.client.as_channel()
1565    }
1566}
1567
1568#[cfg(target_os = "fuchsia")]
1569impl RuleIteratorSynchronousProxy {
1570    pub fn new(channel: fidl::Channel) -> Self {
1571        let protocol_name = <RuleIteratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1572        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1573    }
1574
1575    pub fn into_channel(self) -> fidl::Channel {
1576        self.client.into_channel()
1577    }
1578
1579    /// Waits until an event arrives and returns it. It is safe for other
1580    /// threads to make concurrent requests while waiting for an event.
1581    pub fn wait_for_event(
1582        &self,
1583        deadline: zx::MonotonicInstant,
1584    ) -> Result<RuleIteratorEvent, fidl::Error> {
1585        RuleIteratorEvent::decode(self.client.wait_for_event(deadline)?)
1586    }
1587
1588    /// Advances the iterator and returns the next batch of rules.
1589    ///
1590    /// - response `rules` a vector of [`Rule`] rules. Will return an empty
1591    ///    vector and then close the channel when there are no more rules.
1592    pub fn r#next(&self, ___deadline: zx::MonotonicInstant) -> Result<Vec<Rule>, fidl::Error> {
1593        let _response =
1594            self.client.send_query::<fidl::encoding::EmptyPayload, RuleIteratorNextResponse>(
1595                (),
1596                0x1007ff472e2fcd45,
1597                fidl::encoding::DynamicFlags::empty(),
1598                ___deadline,
1599            )?;
1600        Ok(_response.rules)
1601    }
1602}
1603
1604#[cfg(target_os = "fuchsia")]
1605impl From<RuleIteratorSynchronousProxy> for zx::Handle {
1606    fn from(value: RuleIteratorSynchronousProxy) -> Self {
1607        value.into_channel().into()
1608    }
1609}
1610
1611#[cfg(target_os = "fuchsia")]
1612impl From<fidl::Channel> for RuleIteratorSynchronousProxy {
1613    fn from(value: fidl::Channel) -> Self {
1614        Self::new(value)
1615    }
1616}
1617
1618#[derive(Debug, Clone)]
1619pub struct RuleIteratorProxy {
1620    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1621}
1622
1623impl fidl::endpoints::Proxy for RuleIteratorProxy {
1624    type Protocol = RuleIteratorMarker;
1625
1626    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1627        Self::new(inner)
1628    }
1629
1630    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1631        self.client.into_channel().map_err(|client| Self { client })
1632    }
1633
1634    fn as_channel(&self) -> &::fidl::AsyncChannel {
1635        self.client.as_channel()
1636    }
1637}
1638
1639impl RuleIteratorProxy {
1640    /// Create a new Proxy for fuchsia.pkg.rewrite/RuleIterator.
1641    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1642        let protocol_name = <RuleIteratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1643        Self { client: fidl::client::Client::new(channel, protocol_name) }
1644    }
1645
1646    /// Get a Stream of events from the remote end of the protocol.
1647    ///
1648    /// # Panics
1649    ///
1650    /// Panics if the event stream was already taken.
1651    pub fn take_event_stream(&self) -> RuleIteratorEventStream {
1652        RuleIteratorEventStream { event_receiver: self.client.take_event_receiver() }
1653    }
1654
1655    /// Advances the iterator and returns the next batch of rules.
1656    ///
1657    /// - response `rules` a vector of [`Rule`] rules. Will return an empty
1658    ///    vector and then close the channel when there are no more rules.
1659    pub fn r#next(
1660        &self,
1661    ) -> fidl::client::QueryResponseFut<Vec<Rule>, fidl::encoding::DefaultFuchsiaResourceDialect>
1662    {
1663        RuleIteratorProxyInterface::r#next(self)
1664    }
1665}
1666
1667impl RuleIteratorProxyInterface for RuleIteratorProxy {
1668    type NextResponseFut =
1669        fidl::client::QueryResponseFut<Vec<Rule>, fidl::encoding::DefaultFuchsiaResourceDialect>;
1670    fn r#next(&self) -> Self::NextResponseFut {
1671        fn _decode(
1672            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1673        ) -> Result<Vec<Rule>, fidl::Error> {
1674            let _response = fidl::client::decode_transaction_body::<
1675                RuleIteratorNextResponse,
1676                fidl::encoding::DefaultFuchsiaResourceDialect,
1677                0x1007ff472e2fcd45,
1678            >(_buf?)?;
1679            Ok(_response.rules)
1680        }
1681        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Vec<Rule>>(
1682            (),
1683            0x1007ff472e2fcd45,
1684            fidl::encoding::DynamicFlags::empty(),
1685            _decode,
1686        )
1687    }
1688}
1689
1690pub struct RuleIteratorEventStream {
1691    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1692}
1693
1694impl std::marker::Unpin for RuleIteratorEventStream {}
1695
1696impl futures::stream::FusedStream for RuleIteratorEventStream {
1697    fn is_terminated(&self) -> bool {
1698        self.event_receiver.is_terminated()
1699    }
1700}
1701
1702impl futures::Stream for RuleIteratorEventStream {
1703    type Item = Result<RuleIteratorEvent, fidl::Error>;
1704
1705    fn poll_next(
1706        mut self: std::pin::Pin<&mut Self>,
1707        cx: &mut std::task::Context<'_>,
1708    ) -> std::task::Poll<Option<Self::Item>> {
1709        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1710            &mut self.event_receiver,
1711            cx
1712        )?) {
1713            Some(buf) => std::task::Poll::Ready(Some(RuleIteratorEvent::decode(buf))),
1714            None => std::task::Poll::Ready(None),
1715        }
1716    }
1717}
1718
1719#[derive(Debug)]
1720pub enum RuleIteratorEvent {}
1721
1722impl RuleIteratorEvent {
1723    /// Decodes a message buffer as a [`RuleIteratorEvent`].
1724    fn decode(
1725        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1726    ) -> Result<RuleIteratorEvent, fidl::Error> {
1727        let (bytes, _handles) = buf.split_mut();
1728        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1729        debug_assert_eq!(tx_header.tx_id, 0);
1730        match tx_header.ordinal {
1731            _ => Err(fidl::Error::UnknownOrdinal {
1732                ordinal: tx_header.ordinal,
1733                protocol_name: <RuleIteratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1734            }),
1735        }
1736    }
1737}
1738
1739/// A Stream of incoming requests for fuchsia.pkg.rewrite/RuleIterator.
1740pub struct RuleIteratorRequestStream {
1741    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1742    is_terminated: bool,
1743}
1744
1745impl std::marker::Unpin for RuleIteratorRequestStream {}
1746
1747impl futures::stream::FusedStream for RuleIteratorRequestStream {
1748    fn is_terminated(&self) -> bool {
1749        self.is_terminated
1750    }
1751}
1752
1753impl fidl::endpoints::RequestStream for RuleIteratorRequestStream {
1754    type Protocol = RuleIteratorMarker;
1755    type ControlHandle = RuleIteratorControlHandle;
1756
1757    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1758        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1759    }
1760
1761    fn control_handle(&self) -> Self::ControlHandle {
1762        RuleIteratorControlHandle { inner: self.inner.clone() }
1763    }
1764
1765    fn into_inner(
1766        self,
1767    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1768    {
1769        (self.inner, self.is_terminated)
1770    }
1771
1772    fn from_inner(
1773        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1774        is_terminated: bool,
1775    ) -> Self {
1776        Self { inner, is_terminated }
1777    }
1778}
1779
1780impl futures::Stream for RuleIteratorRequestStream {
1781    type Item = Result<RuleIteratorRequest, fidl::Error>;
1782
1783    fn poll_next(
1784        mut self: std::pin::Pin<&mut Self>,
1785        cx: &mut std::task::Context<'_>,
1786    ) -> std::task::Poll<Option<Self::Item>> {
1787        let this = &mut *self;
1788        if this.inner.check_shutdown(cx) {
1789            this.is_terminated = true;
1790            return std::task::Poll::Ready(None);
1791        }
1792        if this.is_terminated {
1793            panic!("polled RuleIteratorRequestStream after completion");
1794        }
1795        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1796            |bytes, handles| {
1797                match this.inner.channel().read_etc(cx, bytes, handles) {
1798                    std::task::Poll::Ready(Ok(())) => {}
1799                    std::task::Poll::Pending => return std::task::Poll::Pending,
1800                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1801                        this.is_terminated = true;
1802                        return std::task::Poll::Ready(None);
1803                    }
1804                    std::task::Poll::Ready(Err(e)) => {
1805                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1806                            e.into(),
1807                        ))))
1808                    }
1809                }
1810
1811                // A message has been received from the channel
1812                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1813
1814                std::task::Poll::Ready(Some(match header.ordinal {
1815                    0x1007ff472e2fcd45 => {
1816                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1817                        let mut req = fidl::new_empty!(
1818                            fidl::encoding::EmptyPayload,
1819                            fidl::encoding::DefaultFuchsiaResourceDialect
1820                        );
1821                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1822                        let control_handle =
1823                            RuleIteratorControlHandle { inner: this.inner.clone() };
1824                        Ok(RuleIteratorRequest::Next {
1825                            responder: RuleIteratorNextResponder {
1826                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1827                                tx_id: header.tx_id,
1828                            },
1829                        })
1830                    }
1831                    _ => Err(fidl::Error::UnknownOrdinal {
1832                        ordinal: header.ordinal,
1833                        protocol_name:
1834                            <RuleIteratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1835                    }),
1836                }))
1837            },
1838        )
1839    }
1840}
1841
1842/// The iterator over all the rewrite rules defined in a [`Engine`].
1843#[derive(Debug)]
1844pub enum RuleIteratorRequest {
1845    /// Advances the iterator and returns the next batch of rules.
1846    ///
1847    /// - response `rules` a vector of [`Rule`] rules. Will return an empty
1848    ///    vector and then close the channel when there are no more rules.
1849    Next { responder: RuleIteratorNextResponder },
1850}
1851
1852impl RuleIteratorRequest {
1853    #[allow(irrefutable_let_patterns)]
1854    pub fn into_next(self) -> Option<(RuleIteratorNextResponder)> {
1855        if let RuleIteratorRequest::Next { responder } = self {
1856            Some((responder))
1857        } else {
1858            None
1859        }
1860    }
1861
1862    /// Name of the method defined in FIDL
1863    pub fn method_name(&self) -> &'static str {
1864        match *self {
1865            RuleIteratorRequest::Next { .. } => "next",
1866        }
1867    }
1868}
1869
1870#[derive(Debug, Clone)]
1871pub struct RuleIteratorControlHandle {
1872    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1873}
1874
1875impl fidl::endpoints::ControlHandle for RuleIteratorControlHandle {
1876    fn shutdown(&self) {
1877        self.inner.shutdown()
1878    }
1879    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1880        self.inner.shutdown_with_epitaph(status)
1881    }
1882
1883    fn is_closed(&self) -> bool {
1884        self.inner.channel().is_closed()
1885    }
1886    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1887        self.inner.channel().on_closed()
1888    }
1889
1890    #[cfg(target_os = "fuchsia")]
1891    fn signal_peer(
1892        &self,
1893        clear_mask: zx::Signals,
1894        set_mask: zx::Signals,
1895    ) -> Result<(), zx_status::Status> {
1896        use fidl::Peered;
1897        self.inner.channel().signal_peer(clear_mask, set_mask)
1898    }
1899}
1900
1901impl RuleIteratorControlHandle {}
1902
1903#[must_use = "FIDL methods require a response to be sent"]
1904#[derive(Debug)]
1905pub struct RuleIteratorNextResponder {
1906    control_handle: std::mem::ManuallyDrop<RuleIteratorControlHandle>,
1907    tx_id: u32,
1908}
1909
1910/// Set the the channel to be shutdown (see [`RuleIteratorControlHandle::shutdown`])
1911/// if the responder is dropped without sending a response, so that the client
1912/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1913impl std::ops::Drop for RuleIteratorNextResponder {
1914    fn drop(&mut self) {
1915        self.control_handle.shutdown();
1916        // Safety: drops once, never accessed again
1917        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1918    }
1919}
1920
1921impl fidl::endpoints::Responder for RuleIteratorNextResponder {
1922    type ControlHandle = RuleIteratorControlHandle;
1923
1924    fn control_handle(&self) -> &RuleIteratorControlHandle {
1925        &self.control_handle
1926    }
1927
1928    fn drop_without_shutdown(mut self) {
1929        // Safety: drops once, never accessed again due to mem::forget
1930        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1931        // Prevent Drop from running (which would shut down the channel)
1932        std::mem::forget(self);
1933    }
1934}
1935
1936impl RuleIteratorNextResponder {
1937    /// Sends a response to the FIDL transaction.
1938    ///
1939    /// Sets the channel to shutdown if an error occurs.
1940    pub fn send(self, mut rules: &[Rule]) -> Result<(), fidl::Error> {
1941        let _result = self.send_raw(rules);
1942        if _result.is_err() {
1943            self.control_handle.shutdown();
1944        }
1945        self.drop_without_shutdown();
1946        _result
1947    }
1948
1949    /// Similar to "send" but does not shutdown the channel if an error occurs.
1950    pub fn send_no_shutdown_on_err(self, mut rules: &[Rule]) -> Result<(), fidl::Error> {
1951        let _result = self.send_raw(rules);
1952        self.drop_without_shutdown();
1953        _result
1954    }
1955
1956    fn send_raw(&self, mut rules: &[Rule]) -> Result<(), fidl::Error> {
1957        self.control_handle.inner.send::<RuleIteratorNextResponse>(
1958            (rules,),
1959            self.tx_id,
1960            0x1007ff472e2fcd45,
1961            fidl::encoding::DynamicFlags::empty(),
1962        )
1963    }
1964}
1965
1966mod internal {
1967    use super::*;
1968
1969    impl fidl::encoding::ResourceTypeMarker for EditTransactionListDynamicRequest {
1970        type Borrowed<'a> = &'a mut Self;
1971        fn take_or_borrow<'a>(
1972            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1973        ) -> Self::Borrowed<'a> {
1974            value
1975        }
1976    }
1977
1978    unsafe impl fidl::encoding::TypeMarker for EditTransactionListDynamicRequest {
1979        type Owned = Self;
1980
1981        #[inline(always)]
1982        fn inline_align(_context: fidl::encoding::Context) -> usize {
1983            4
1984        }
1985
1986        #[inline(always)]
1987        fn inline_size(_context: fidl::encoding::Context) -> usize {
1988            4
1989        }
1990    }
1991
1992    unsafe impl
1993        fidl::encoding::Encode<
1994            EditTransactionListDynamicRequest,
1995            fidl::encoding::DefaultFuchsiaResourceDialect,
1996        > for &mut EditTransactionListDynamicRequest
1997    {
1998        #[inline]
1999        unsafe fn encode(
2000            self,
2001            encoder: &mut fidl::encoding::Encoder<
2002                '_,
2003                fidl::encoding::DefaultFuchsiaResourceDialect,
2004            >,
2005            offset: usize,
2006            _depth: fidl::encoding::Depth,
2007        ) -> fidl::Result<()> {
2008            encoder.debug_check_bounds::<EditTransactionListDynamicRequest>(offset);
2009            // Delegate to tuple encoding.
2010            fidl::encoding::Encode::<EditTransactionListDynamicRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
2011                (
2012                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.iterator),
2013                ),
2014                encoder, offset, _depth
2015            )
2016        }
2017    }
2018    unsafe impl<
2019            T0: fidl::encoding::Encode<
2020                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>>,
2021                fidl::encoding::DefaultFuchsiaResourceDialect,
2022            >,
2023        >
2024        fidl::encoding::Encode<
2025            EditTransactionListDynamicRequest,
2026            fidl::encoding::DefaultFuchsiaResourceDialect,
2027        > for (T0,)
2028    {
2029        #[inline]
2030        unsafe fn encode(
2031            self,
2032            encoder: &mut fidl::encoding::Encoder<
2033                '_,
2034                fidl::encoding::DefaultFuchsiaResourceDialect,
2035            >,
2036            offset: usize,
2037            depth: fidl::encoding::Depth,
2038        ) -> fidl::Result<()> {
2039            encoder.debug_check_bounds::<EditTransactionListDynamicRequest>(offset);
2040            // Zero out padding regions. There's no need to apply masks
2041            // because the unmasked parts will be overwritten by fields.
2042            // Write the fields.
2043            self.0.encode(encoder, offset + 0, depth)?;
2044            Ok(())
2045        }
2046    }
2047
2048    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2049        for EditTransactionListDynamicRequest
2050    {
2051        #[inline(always)]
2052        fn new_empty() -> Self {
2053            Self {
2054                iterator: fidl::new_empty!(
2055                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>>,
2056                    fidl::encoding::DefaultFuchsiaResourceDialect
2057                ),
2058            }
2059        }
2060
2061        #[inline]
2062        unsafe fn decode(
2063            &mut self,
2064            decoder: &mut fidl::encoding::Decoder<
2065                '_,
2066                fidl::encoding::DefaultFuchsiaResourceDialect,
2067            >,
2068            offset: usize,
2069            _depth: fidl::encoding::Depth,
2070        ) -> fidl::Result<()> {
2071            decoder.debug_check_bounds::<Self>(offset);
2072            // Verify that padding bytes are zero.
2073            fidl::decode!(
2074                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>>,
2075                fidl::encoding::DefaultFuchsiaResourceDialect,
2076                &mut self.iterator,
2077                decoder,
2078                offset + 0,
2079                _depth
2080            )?;
2081            Ok(())
2082        }
2083    }
2084
2085    impl fidl::encoding::ResourceTypeMarker for EngineListRequest {
2086        type Borrowed<'a> = &'a mut Self;
2087        fn take_or_borrow<'a>(
2088            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2089        ) -> Self::Borrowed<'a> {
2090            value
2091        }
2092    }
2093
2094    unsafe impl fidl::encoding::TypeMarker for EngineListRequest {
2095        type Owned = Self;
2096
2097        #[inline(always)]
2098        fn inline_align(_context: fidl::encoding::Context) -> usize {
2099            4
2100        }
2101
2102        #[inline(always)]
2103        fn inline_size(_context: fidl::encoding::Context) -> usize {
2104            4
2105        }
2106    }
2107
2108    unsafe impl
2109        fidl::encoding::Encode<EngineListRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
2110        for &mut EngineListRequest
2111    {
2112        #[inline]
2113        unsafe fn encode(
2114            self,
2115            encoder: &mut fidl::encoding::Encoder<
2116                '_,
2117                fidl::encoding::DefaultFuchsiaResourceDialect,
2118            >,
2119            offset: usize,
2120            _depth: fidl::encoding::Depth,
2121        ) -> fidl::Result<()> {
2122            encoder.debug_check_bounds::<EngineListRequest>(offset);
2123            // Delegate to tuple encoding.
2124            fidl::encoding::Encode::<EngineListRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
2125                (
2126                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.iterator),
2127                ),
2128                encoder, offset, _depth
2129            )
2130        }
2131    }
2132    unsafe impl<
2133            T0: fidl::encoding::Encode<
2134                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>>,
2135                fidl::encoding::DefaultFuchsiaResourceDialect,
2136            >,
2137        >
2138        fidl::encoding::Encode<EngineListRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
2139        for (T0,)
2140    {
2141        #[inline]
2142        unsafe fn encode(
2143            self,
2144            encoder: &mut fidl::encoding::Encoder<
2145                '_,
2146                fidl::encoding::DefaultFuchsiaResourceDialect,
2147            >,
2148            offset: usize,
2149            depth: fidl::encoding::Depth,
2150        ) -> fidl::Result<()> {
2151            encoder.debug_check_bounds::<EngineListRequest>(offset);
2152            // Zero out padding regions. There's no need to apply masks
2153            // because the unmasked parts will be overwritten by fields.
2154            // Write the fields.
2155            self.0.encode(encoder, offset + 0, depth)?;
2156            Ok(())
2157        }
2158    }
2159
2160    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2161        for EngineListRequest
2162    {
2163        #[inline(always)]
2164        fn new_empty() -> Self {
2165            Self {
2166                iterator: fidl::new_empty!(
2167                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>>,
2168                    fidl::encoding::DefaultFuchsiaResourceDialect
2169                ),
2170            }
2171        }
2172
2173        #[inline]
2174        unsafe fn decode(
2175            &mut self,
2176            decoder: &mut fidl::encoding::Decoder<
2177                '_,
2178                fidl::encoding::DefaultFuchsiaResourceDialect,
2179            >,
2180            offset: usize,
2181            _depth: fidl::encoding::Depth,
2182        ) -> fidl::Result<()> {
2183            decoder.debug_check_bounds::<Self>(offset);
2184            // Verify that padding bytes are zero.
2185            fidl::decode!(
2186                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>>,
2187                fidl::encoding::DefaultFuchsiaResourceDialect,
2188                &mut self.iterator,
2189                decoder,
2190                offset + 0,
2191                _depth
2192            )?;
2193            Ok(())
2194        }
2195    }
2196
2197    impl fidl::encoding::ResourceTypeMarker for EngineListStaticRequest {
2198        type Borrowed<'a> = &'a mut Self;
2199        fn take_or_borrow<'a>(
2200            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2201        ) -> Self::Borrowed<'a> {
2202            value
2203        }
2204    }
2205
2206    unsafe impl fidl::encoding::TypeMarker for EngineListStaticRequest {
2207        type Owned = Self;
2208
2209        #[inline(always)]
2210        fn inline_align(_context: fidl::encoding::Context) -> usize {
2211            4
2212        }
2213
2214        #[inline(always)]
2215        fn inline_size(_context: fidl::encoding::Context) -> usize {
2216            4
2217        }
2218    }
2219
2220    unsafe impl
2221        fidl::encoding::Encode<
2222            EngineListStaticRequest,
2223            fidl::encoding::DefaultFuchsiaResourceDialect,
2224        > for &mut EngineListStaticRequest
2225    {
2226        #[inline]
2227        unsafe fn encode(
2228            self,
2229            encoder: &mut fidl::encoding::Encoder<
2230                '_,
2231                fidl::encoding::DefaultFuchsiaResourceDialect,
2232            >,
2233            offset: usize,
2234            _depth: fidl::encoding::Depth,
2235        ) -> fidl::Result<()> {
2236            encoder.debug_check_bounds::<EngineListStaticRequest>(offset);
2237            // Delegate to tuple encoding.
2238            fidl::encoding::Encode::<EngineListStaticRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
2239                (
2240                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.iterator),
2241                ),
2242                encoder, offset, _depth
2243            )
2244        }
2245    }
2246    unsafe impl<
2247            T0: fidl::encoding::Encode<
2248                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>>,
2249                fidl::encoding::DefaultFuchsiaResourceDialect,
2250            >,
2251        >
2252        fidl::encoding::Encode<
2253            EngineListStaticRequest,
2254            fidl::encoding::DefaultFuchsiaResourceDialect,
2255        > for (T0,)
2256    {
2257        #[inline]
2258        unsafe fn encode(
2259            self,
2260            encoder: &mut fidl::encoding::Encoder<
2261                '_,
2262                fidl::encoding::DefaultFuchsiaResourceDialect,
2263            >,
2264            offset: usize,
2265            depth: fidl::encoding::Depth,
2266        ) -> fidl::Result<()> {
2267            encoder.debug_check_bounds::<EngineListStaticRequest>(offset);
2268            // Zero out padding regions. There's no need to apply masks
2269            // because the unmasked parts will be overwritten by fields.
2270            // Write the fields.
2271            self.0.encode(encoder, offset + 0, depth)?;
2272            Ok(())
2273        }
2274    }
2275
2276    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2277        for EngineListStaticRequest
2278    {
2279        #[inline(always)]
2280        fn new_empty() -> Self {
2281            Self {
2282                iterator: fidl::new_empty!(
2283                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>>,
2284                    fidl::encoding::DefaultFuchsiaResourceDialect
2285                ),
2286            }
2287        }
2288
2289        #[inline]
2290        unsafe fn decode(
2291            &mut self,
2292            decoder: &mut fidl::encoding::Decoder<
2293                '_,
2294                fidl::encoding::DefaultFuchsiaResourceDialect,
2295            >,
2296            offset: usize,
2297            _depth: fidl::encoding::Depth,
2298        ) -> fidl::Result<()> {
2299            decoder.debug_check_bounds::<Self>(offset);
2300            // Verify that padding bytes are zero.
2301            fidl::decode!(
2302                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<RuleIteratorMarker>>,
2303                fidl::encoding::DefaultFuchsiaResourceDialect,
2304                &mut self.iterator,
2305                decoder,
2306                offset + 0,
2307                _depth
2308            )?;
2309            Ok(())
2310        }
2311    }
2312
2313    impl fidl::encoding::ResourceTypeMarker for EngineStartEditTransactionRequest {
2314        type Borrowed<'a> = &'a mut Self;
2315        fn take_or_borrow<'a>(
2316            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2317        ) -> Self::Borrowed<'a> {
2318            value
2319        }
2320    }
2321
2322    unsafe impl fidl::encoding::TypeMarker for EngineStartEditTransactionRequest {
2323        type Owned = Self;
2324
2325        #[inline(always)]
2326        fn inline_align(_context: fidl::encoding::Context) -> usize {
2327            4
2328        }
2329
2330        #[inline(always)]
2331        fn inline_size(_context: fidl::encoding::Context) -> usize {
2332            4
2333        }
2334    }
2335
2336    unsafe impl
2337        fidl::encoding::Encode<
2338            EngineStartEditTransactionRequest,
2339            fidl::encoding::DefaultFuchsiaResourceDialect,
2340        > for &mut EngineStartEditTransactionRequest
2341    {
2342        #[inline]
2343        unsafe fn encode(
2344            self,
2345            encoder: &mut fidl::encoding::Encoder<
2346                '_,
2347                fidl::encoding::DefaultFuchsiaResourceDialect,
2348            >,
2349            offset: usize,
2350            _depth: fidl::encoding::Depth,
2351        ) -> fidl::Result<()> {
2352            encoder.debug_check_bounds::<EngineStartEditTransactionRequest>(offset);
2353            // Delegate to tuple encoding.
2354            fidl::encoding::Encode::<EngineStartEditTransactionRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
2355                (
2356                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<EditTransactionMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.transaction),
2357                ),
2358                encoder, offset, _depth
2359            )
2360        }
2361    }
2362    unsafe impl<
2363            T0: fidl::encoding::Encode<
2364                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<EditTransactionMarker>>,
2365                fidl::encoding::DefaultFuchsiaResourceDialect,
2366            >,
2367        >
2368        fidl::encoding::Encode<
2369            EngineStartEditTransactionRequest,
2370            fidl::encoding::DefaultFuchsiaResourceDialect,
2371        > for (T0,)
2372    {
2373        #[inline]
2374        unsafe fn encode(
2375            self,
2376            encoder: &mut fidl::encoding::Encoder<
2377                '_,
2378                fidl::encoding::DefaultFuchsiaResourceDialect,
2379            >,
2380            offset: usize,
2381            depth: fidl::encoding::Depth,
2382        ) -> fidl::Result<()> {
2383            encoder.debug_check_bounds::<EngineStartEditTransactionRequest>(offset);
2384            // Zero out padding regions. There's no need to apply masks
2385            // because the unmasked parts will be overwritten by fields.
2386            // Write the fields.
2387            self.0.encode(encoder, offset + 0, depth)?;
2388            Ok(())
2389        }
2390    }
2391
2392    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2393        for EngineStartEditTransactionRequest
2394    {
2395        #[inline(always)]
2396        fn new_empty() -> Self {
2397            Self {
2398                transaction: fidl::new_empty!(
2399                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<EditTransactionMarker>>,
2400                    fidl::encoding::DefaultFuchsiaResourceDialect
2401                ),
2402            }
2403        }
2404
2405        #[inline]
2406        unsafe fn decode(
2407            &mut self,
2408            decoder: &mut fidl::encoding::Decoder<
2409                '_,
2410                fidl::encoding::DefaultFuchsiaResourceDialect,
2411            >,
2412            offset: usize,
2413            _depth: fidl::encoding::Depth,
2414        ) -> fidl::Result<()> {
2415            decoder.debug_check_bounds::<Self>(offset);
2416            // Verify that padding bytes are zero.
2417            fidl::decode!(
2418                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<EditTransactionMarker>>,
2419                fidl::encoding::DefaultFuchsiaResourceDialect,
2420                &mut self.transaction,
2421                decoder,
2422                offset + 0,
2423                _depth
2424            )?;
2425            Ok(())
2426        }
2427    }
2428}