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