Skip to main content

ridl_rt/
port.rs

1//! The ports: the traits a runtime implements and generated code calls.
2//!
3//! Every port method returns without waiting. Waiting — blocking, `async`, or
4//! a loop that drives the runtime — belongs to a face over a port, and this
5//! crate defines no face. A port carries interface numbers, ordinals and
6//! bytes, never a payload type: the generated binding decodes. No port method
7//! takes the current time; a runtime reads its own [`Clock`].
8//!
9//! A port is attached to one catalog ([`Attached`]), and the interface numbers
10//! and ordinals its methods take are scoped by that catalog.
11//!
12//! [`ScannableSignals`] and [`CoherentSignals`] are extensions. They describe
13//! mechanisms some runtimes have, not interaction semantics every runtime must
14//! present, so a runtime may omit them.
15//!
16//! Each trait below names the generated method it backs, so a reader who
17//! arrived from generated code can find the port under it. The crate-level
18//! documentation has the whole table, and
19//! `docs/technotes/ridl-rt-by-example.md` in this repository walks it against
20//! concrete generated code.
21
22use crate::contract::{CatalogRef, InterfaceNo, Ordinal};
23use crate::error::{CallError, Contract};
24use crate::sample::{Duration, Envelope, Freshness, Provenance, Timestamp};
25
26/// A port attached to one catalog.
27pub trait Attached {
28    /// The catalog this port serves.
29    fn catalog(&self) -> &CatalogRef;
30}
31
32/// The clock envelopes are stamped from. A runtime has one.
33pub trait Clock {
34    /// The current time in the platform time base.
35    fn now(&self) -> Timestamp;
36}
37
38/// Signals, consumer side.
39///
40/// A generated `Client` has one method per signal over this port. It reads
41/// into a stack buffer sized from the payload's
42/// [`MAX_SIZE`](crate::payload::Payload::MAX_SIZE), checks the bytes, and
43/// returns a [`Sample`](crate::sample::Sample). Bytes that fail their check
44/// are not an error there: the sample carries the channel's init value and a
45/// provenance of [`Invalid`](crate::sample::Provenance::Invalid), so the
46/// [`ReadError`] here reports the read itself.
47pub trait SignalReader: Attached {
48    /// Copies the signal's current value into the front of `out` and returns
49    /// its provenance, its freshness and its envelope. The runtime resolves
50    /// both the provenance and the freshness.
51    ///
52    /// Returns `ReadError::Short` when `out` is shorter than the value.
53    fn read(
54        &self,
55        iface: InterfaceNo,
56        ord: Ordinal,
57        out: &mut [u8],
58    ) -> Result<RawSample, ReadError>;
59}
60
61/// What [`SignalReader::read`] returns beside the copied bytes.
62#[derive(Clone, Copy, Debug, PartialEq, Eq)]
63pub struct RawSample {
64    /// Where the value comes from.
65    pub provenance: Provenance,
66    /// How old the value is.
67    pub freshness: Freshness,
68    /// The sender's timestamp and sequence number.
69    pub envelope: Envelope,
70    /// The number of bytes copied into `out`.
71    pub len: usize,
72}
73
74/// Signals, provider side.
75///
76/// `set`, `invalidate` and `touch` stage a change. Each fails with
77/// [`WriteError::Contract`] when the ordinal names no member, and with
78/// [`WriteError::NotOwner`] when it names a member this provider does not
79/// own. `commit` publishes every staged change, with one generation
80/// increment and one timestamp per interface, taken from the runtime's
81/// [`Clock`].
82///
83/// A generated `Publisher` has one method per signal over `set`, plus an
84/// `invalidate_<name>` and a `commit`. The staging split is why a provider
85/// that updates several signals of one interface and then commits produces one
86/// coherent publication rather than several.
87pub trait SignalWriter: Attached {
88    /// Stages a new value.
89    fn set(&mut self, iface: InterfaceNo, ord: Ordinal, bytes: &[u8]) -> Result<(), WriteError>;
90    /// Stages the invalid state (ridl §4.5), with
91    /// [`Cause::Declared`](crate::sample::Cause::Declared).
92    fn invalidate(&mut self, iface: InterfaceNo, ord: Ordinal) -> Result<(), WriteError>;
93    /// Stages a re-affirmation of the current value, without a new value.
94    fn touch(&mut self, iface: InterfaceNo, ord: Ordinal) -> Result<(), WriteError>;
95    /// Publishes everything staged. It cannot fail, so it reports nothing —
96    /// including that the runtime behind the port is gone. A caller learns
97    /// that from [`WriteError::Detached`] on a later `set`, `invalidate` or
98    /// `touch`, never from that `commit`. What becomes of the changes staged
99    /// before a commit whose runtime has already detached is not fixed here.
100    fn commit(&mut self);
101}
102
103/// Events, consumer side.
104///
105/// A generated `Client` has a `subscribe_<name>` per event, but a single
106/// `next_event` for the whole interface, because [`next`](EventSource::next)
107/// returns the next occurrence of anything subscribed and the payload type is
108/// not known until its ordinal has been read. The generated method routes on
109/// that ordinal into an enum with one variant per event.
110pub trait EventSource: Attached {
111    /// Starts delivery of the listed events.
112    fn subscribe(&mut self, iface: InterfaceNo, ords: &[Ordinal]) -> Result<(), SubscribeError>;
113    /// Stops delivery of the listed events.
114    fn unsubscribe(&mut self, iface: InterfaceNo, ords: &[Ordinal]);
115    /// Copies the next occurrence into the front of `out`. `Ok(None)` when no
116    /// occurrence is waiting.
117    ///
118    /// Occurrences come in order, and a gap in `seq` is a loss (ridl §3.1). An
119    /// occurrence older than its time to live is discarded here (ridl §5.2).
120    /// `ReadError::Short` does not consume the occurrence: the next call
121    /// returns the same one.
122    fn next(&mut self, out: &mut [u8]) -> Result<Option<RawOccurrence>, ReadError>;
123}
124
125/// What [`EventSource::next`] returns beside the copied bytes.
126#[derive(Clone, Copy, Debug, PartialEq, Eq)]
127pub struct RawOccurrence {
128    /// The interface of the event.
129    pub iface: InterfaceNo,
130    /// The ordinal of the event.
131    pub ord: Ordinal,
132    /// The sender's timestamp and sequence number.
133    pub envelope: Envelope,
134    /// The number of bytes copied into `out`.
135    pub len: usize,
136}
137
138/// Events, provider side.
139///
140/// A generated `Publisher` has one method per event over this port. Unlike a
141/// signal, an occurrence is not staged and there is no `commit`: there is no
142/// coherent set to assemble.
143pub trait EventSink: Attached {
144    /// Raises one occurrence.
145    fn raise(&mut self, iface: InterfaceNo, ord: Ordinal, bytes: &[u8]) -> Result<(), RaiseError>;
146}
147
148/// Calls, consumer side.
149///
150/// A command and a query are separate methods, because their outcomes differ
151/// (ridl §6, §7).
152///
153/// A generated `Client` has one method per command and query over this port,
154/// each returning a [`Correlation`] rather than an outcome, because nothing
155/// here waits. The outcome is retrieved separately: [`ack`](Caller::ack) for a
156/// command, a generated `<name>_reply` over [`reply`](Caller::reply) for a
157/// query. A `require` clause is evaluated before sending, so a failing
158/// precondition costs no round trip and is reported as
159/// [`SendError::Contract`].
160pub trait Caller: Attached {
161    /// Sends a command and returns the correlation of its outcome.
162    fn command(
163        &mut self,
164        iface: InterfaceNo,
165        ord: Ordinal,
166        args: &[u8],
167    ) -> Result<Correlation, SendError>;
168    /// Sends a query and returns the correlation of its reply.
169    fn query(
170        &mut self,
171        iface: InterfaceNo,
172        ord: Ordinal,
173        args: &[u8],
174    ) -> Result<Correlation, SendError>;
175    /// A command's delivery acknowledgment (ridl §6.1), once it is known:
176    /// `Ok(())` when accepted, `Err(CallError::Contract(_))` when rejected,
177    /// `Err(CallError::Transport(Transport::Corrupt))` when the provider could
178    /// not read the command's argument bytes, and
179    /// `Err(CallError::Transport(Transport::Undelivered))` when no
180    /// acknowledgment came within the bound. `None` while unknown, and always
181    /// `None` for a query's correlation.
182    ///
183    /// `None` has two causes this method does not separate: the acknowledgment
184    /// is not known yet, and `c` is a query's correlation, for which `None` is
185    /// the standing answer. A caller that polls `ack` for a query's
186    /// correlation therefore never finishes. The return carries no error, so
187    /// keep the correlations [`command`](Caller::command) returned and ask
188    /// only about those. After [`forget`](Caller::forget) a correlation's
189    /// outcome is no longer retrievable, so do not ask about it.
190    fn ack(&mut self, c: Correlation) -> Option<Result<(), CallError>>;
191    /// A query's reply, once it is known: the reply bytes copied into the front
192    /// of `out` and their length, or the error. `Ok(None)` while unknown.
193    /// `ReadError::Short` does not consume the reply.
194    ///
195    /// The outer [`ReadError`] reports the port call itself: `Short` when
196    /// `out` is too short, and `Detached` when the local runtime is gone.
197    /// `reply` never returns `ReadError::Contract`. The inner [`CallError`] is
198    /// the outcome from the peer or the transport, such as a contract error
199    /// the provider settled, or `Transport::Down` when the connection to the
200    /// peer is lost.
201    fn reply(
202        &mut self,
203        c: Correlation,
204        out: &mut [u8],
205    ) -> Result<Option<Result<usize, CallError>>, ReadError>;
206    /// Releases a correlation whose outcome the caller no longer needs.
207    fn forget(&mut self, c: Correlation);
208}
209
210/// Identifies one sent call to its caller.
211#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
212pub struct Correlation(pub u64);
213
214/// Calls, provider side.
215///
216/// `next_claim` presents each delivered call once. A retransmission of a call
217/// already presented is not presented again and receives the cached
218/// acknowledgment. Calls from two callers are never merged, even when they
219/// carry the same `seq`. A call lost in transport is never presented. The
220/// caller of a lost command sees `Transport::Undelivered` from `Caller::ack`;
221/// the caller of a lost query sees `Transport::Timeout` from `Caller::reply`
222/// once the response bound passes.
223///
224/// Every claim is settled. For a command, the generated dispatch settles
225/// `Ok(&[])` after the arguments and `require` pass, before application code
226/// runs. For a query, it settles with the reply bytes or the outcome the
227/// caller sees.
228///
229/// An application implements neither this trait nor a claim loop. It
230/// implements the generated `Provider` trait and calls the generated
231/// `dispatch`, which makes one pass over the claims already waiting, routes
232/// each by ordinal, decodes, evaluates `require`, calls the provider,
233/// evaluates a query's `ensure`, settles, and returns how many settlements
234/// this port accepted.
235pub trait Handler: Attached {
236    /// Starts presenting calls to the listed members.
237    fn serve(&mut self, iface: InterfaceNo, ords: &[Ordinal]) -> Result<(), ServeError>;
238    /// Copies the next call's arguments into the front of `out`. `Ok(None)`
239    /// when no call is waiting. `ReadError::Short` does not consume the call.
240    fn next_claim(&mut self, out: &mut [u8]) -> Result<Option<Claim>, ReadError>;
241    /// Settles a claim with the reply bytes (empty for a command) or the
242    /// outcome the caller sees. A provider settles
243    /// [`CallError::Contract`] when the arguments break their typl
244    /// constraints, a `require` clause fails, or an `ensure` clause fails,
245    /// and `CallError::Transport(Transport::Corrupt)` when the argument
246    /// bytes fail the structure check.
247    fn settle(
248        &mut self,
249        claim: ClaimId,
250        outcome: Result<&[u8], CallError>,
251    ) -> Result<(), SettleError>;
252}
253
254/// One call presented to a provider.
255#[derive(Clone, Copy, Debug, PartialEq, Eq)]
256pub struct Claim {
257    /// Unique in its channel.
258    pub id: ClaimId,
259    /// The interface of the call.
260    pub iface: InterfaceNo,
261    /// The ordinal of the call. The descriptor at this ordinal gives the kind.
262    pub ord: Ordinal,
263    /// The caller's timestamp and sequence number. `seq` is unique for each
264    /// caller, not for each channel.
265    pub envelope: Envelope,
266    /// The time left before the response bound passes. `None` when the call
267    /// has no response bound (ridl §9.3).
268    pub remaining: Option<Duration>,
269    /// The number of argument bytes copied into `out`.
270    pub len: usize,
271}
272
273/// Identifies one claim to its provider.
274#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
275pub struct ClaimId(pub u64);
276
277/// `fixed`, consumer side (ridl §8).
278///
279/// The generated face carries no method over this port in this version: a
280/// `fixed` is provisioned rather than interacted with, so the emitter writes
281/// its descriptor and nothing else, and an application that needs a
282/// provisioned value calls [`read_fixed`](FixedReader::read_fixed) itself.
283/// There is no provider side either — a provisioned constant is supplied to
284/// the runtime, not published by application code.
285pub trait FixedReader: Attached {
286    /// Copies the provisioned value into the front of `out` and returns its
287    /// length.
288    fn read_fixed(
289        &self,
290        iface: InterfaceNo,
291        ord: Ordinal,
292        out: &mut [u8],
293    ) -> Result<usize, ReadError>;
294}
295
296/// Extension: signals in a store a consumer can walk. A runtime may omit it.
297pub trait ScannableSignals: SignalReader {
298    /// The interface's generation: a counter that each commit to the interface
299    /// increments.
300    ///
301    /// The return carries no error, so an interface the port's catalog does
302    /// not hold has no reserved answer: it gives a `u64` the caller cannot
303    /// tell from a real generation. Ask only about an interface of
304    /// [`catalog`](Attached::catalog).
305    fn generation(&self, iface: InterfaceNo) -> u64;
306    /// Writes the changes into `out`, interface by interface, in the order of
307    /// `marks`, and updates `marks`. An interface's changes are written all
308    /// together or not at all: when they do not fit in the rest of `out`,
309    /// none of them is written, that interface's mark is not updated, and
310    /// `scan` returns the number of entries written so far.
311    ///
312    /// The count alone does not say whether changes are still waiting, because
313    /// a return of 0 has two causes. To tell them apart, compare each mark
314    /// with its interface's [`generation`](ScannableSignals::generation) after
315    /// the call:
316    ///
317    /// - every mark's `generation` equals `generation(iface)` — nothing had
318    ///   changed, and the scan is complete;
319    /// - some mark's `generation` is behind `generation(iface)` — that
320    ///   interface's changes did not fit in `out`. When `scan` also returned
321    ///   0, `out` is shorter than the changes of the first such interface in
322    ///   the order of `marks`, and no call can make progress until `out` is
323    ///   longer.
324    ///
325    /// A caller that scans in a loop therefore grows `out` when `scan` returns
326    /// 0 and a mark is still behind its interface's generation.
327    fn scan(&self, marks: &mut [Watermark], out: &mut [Changed]) -> usize;
328}
329
330/// How far a consumer has scanned one interface.
331#[derive(Clone, Copy, Debug, PartialEq, Eq)]
332pub struct Watermark {
333    /// The interface.
334    pub iface: InterfaceNo,
335    /// The generation last scanned. Named `generation`, not `gen`, because
336    /// `gen` is a reserved keyword in the 2024 edition.
337    pub generation: u64,
338    /// The sequence number last scanned.
339    pub seq: u64,
340}
341
342/// A signal that changed since a [`Watermark`].
343#[derive(Clone, Copy, Debug, PartialEq, Eq)]
344pub struct Changed {
345    /// The interface of the signal.
346    pub iface: InterfaceNo,
347    /// The ordinal of the signal.
348    pub ord: Ordinal,
349    /// The signal's sequence number.
350    pub seq: u64,
351}
352
353/// Extension: reads of several signals of one interface from one publication.
354/// A runtime whose binding delivers each field separately cannot present this
355/// and omits it.
356pub trait CoherentSignals: SignalReader {
357    /// Answers every ordinal in `ords` from one publication. Copies the values
358    /// into `out` one after another, writes one `RawSample` for each ordinal
359    /// into `samples` in the order of `ords`, and returns the number of bytes
360    /// written to `out`.
361    ///
362    /// Returns `ReadError::Short` with the size the whole set needs when `out`
363    /// is too short, `ReadError::TooFewSamples` with the number of entries
364    /// `samples` needs when `samples` is shorter than `ords`, and
365    /// `ReadError::Contract(Contract::UnknownInteraction)` when an ordinal
366    /// names no member.
367    fn read_coherent(
368        &self,
369        iface: InterfaceNo,
370        ords: &[Ordinal],
371        out: &mut [u8],
372        samples: &mut [RawSample],
373    ) -> Result<usize, ReadError>;
374}
375
376/// A read that failed.
377///
378/// One enum serves every read on every port, so a variant can be unreachable
379/// for the method that returns it: [`TooFewSamples`](ReadError::TooFewSamples)
380/// belongs to [`CoherentSignals::read_coherent`] alone, and
381/// [`Caller::reply`] never returns [`Contract`](ReadError::Contract). Each
382/// method documents what it can return.
383#[non_exhaustive]
384#[derive(Clone, Copy, Debug, PartialEq, Eq)]
385pub enum ReadError {
386    /// The output buffer is too short. Nothing was consumed.
387    Short {
388        /// The bytes the read needs.
389        needed: usize,
390    },
391    /// `samples` has fewer entries than `ords`. Nothing was consumed.
392    TooFewSamples {
393        /// The entries `samples` needs.
394        needed: usize,
395    },
396    /// A contract error, such as an unknown interaction.
397    Contract(Contract),
398    /// The runtime behind the port is gone.
399    Detached,
400}
401
402/// A [`SignalWriter::set`], [`SignalWriter::invalidate`] or
403/// [`SignalWriter::touch`] that failed.
404#[non_exhaustive]
405#[derive(Clone, Copy, Debug, PartialEq, Eq)]
406pub enum WriteError {
407    /// The value is larger than the signal's capacity.
408    TooLarge {
409        /// The capacity in bytes.
410        cap: usize,
411    },
412    /// This provider does not own the signal.
413    NotOwner,
414    /// A contract error, such as an unknown interaction.
415    Contract(Contract),
416    /// The runtime behind the port is gone.
417    Detached,
418}
419
420/// An [`EventSink::raise`] that failed.
421#[non_exhaustive]
422#[derive(Clone, Copy, Debug, PartialEq, Eq)]
423pub enum RaiseError {
424    /// The runtime cannot accept an occurrence now. Retryable.
425    Busy,
426    /// The occurrence is larger than the event's capacity.
427    TooLarge {
428        /// The capacity in bytes.
429        cap: usize,
430    },
431    /// This provider does not own the event.
432    NotOwner,
433    /// A contract error, such as an unknown interaction.
434    Contract(Contract),
435    /// The runtime behind the port is gone.
436    Detached,
437}
438
439/// A [`Caller::command`] or [`Caller::query`] that failed before sending.
440#[non_exhaustive]
441#[derive(Clone, Copy, Debug, PartialEq, Eq)]
442pub enum SendError {
443    /// The runtime cannot accept a call now. Retryable.
444    Busy,
445    /// The arguments are larger than the call's capacity.
446    TooLarge {
447        /// The capacity in bytes.
448        cap: usize,
449    },
450    /// A contract error, such as an unknown interaction.
451    Contract(Contract),
452    /// The runtime behind the port is gone.
453    Detached,
454}
455
456/// An [`EventSource::subscribe`] that failed.
457#[non_exhaustive]
458#[derive(Clone, Copy, Debug, PartialEq, Eq)]
459pub enum SubscribeError {
460    /// A contract error: an unknown interaction fails when subscribing (ridl
461    /// §10.2).
462    Contract(Contract),
463    /// The runtime behind the port is gone.
464    Detached,
465}
466
467/// A [`Handler::serve`] that failed.
468#[non_exhaustive]
469#[derive(Clone, Copy, Debug, PartialEq, Eq)]
470pub enum ServeError {
471    /// A contract error, such as an unknown interaction.
472    Contract(Contract),
473    /// This provider does not own the call.
474    NotOwner,
475    /// The runtime behind the port is gone.
476    Detached,
477}
478
479/// A [`Handler::settle`] that failed.
480#[non_exhaustive]
481#[derive(Clone, Copy, Debug, PartialEq, Eq)]
482pub enum SettleError {
483    /// The claim was already settled, or was never issued.
484    UnknownClaim,
485    /// The reply is larger than the call's capacity.
486    TooLarge {
487        /// The capacity in bytes.
488        cap: usize,
489    },
490    /// The runtime behind the port is gone.
491    Detached,
492}
493
494// Forwarding impls (ADR-0021 decision 11).
495//
496// Every port trait above is implemented for `&mut P`, and the six whose
497// methods all take `&self` — `Attached`, `Clock`, `SignalReader`,
498// `FixedReader`, `ScannableSignals` and `CoherentSignals` — also for `&P`.
499// What they buy is one thing: a value generic over a port trait, such as a
500// generated face, can be built over a reference to a port rather than over the
501// port itself. A wrapper that adds tracing and a test double are accepted by
502// such a bound with or without them, because each implements the port traits
503// itself.
504//
505// `impl<P: T + ?Sized> T for Box<P>` is deferred: it needs `alloc`, which no
506// feature combination of this crate brings in.
507
508impl<P: Attached + ?Sized> Attached for &P {
509    fn catalog(&self) -> &CatalogRef {
510        (**self).catalog()
511    }
512}
513
514impl<P: Attached + ?Sized> Attached for &mut P {
515    fn catalog(&self) -> &CatalogRef {
516        (**self).catalog()
517    }
518}
519
520impl<P: Clock + ?Sized> Clock for &P {
521    fn now(&self) -> Timestamp {
522        (**self).now()
523    }
524}
525
526impl<P: Clock + ?Sized> Clock for &mut P {
527    fn now(&self) -> Timestamp {
528        (**self).now()
529    }
530}
531
532impl<P: SignalReader + ?Sized> SignalReader for &P {
533    fn read(
534        &self,
535        iface: InterfaceNo,
536        ord: Ordinal,
537        out: &mut [u8],
538    ) -> Result<RawSample, ReadError> {
539        (**self).read(iface, ord, out)
540    }
541}
542
543impl<P: SignalReader + ?Sized> SignalReader for &mut P {
544    fn read(
545        &self,
546        iface: InterfaceNo,
547        ord: Ordinal,
548        out: &mut [u8],
549    ) -> Result<RawSample, ReadError> {
550        (**self).read(iface, ord, out)
551    }
552}
553
554impl<P: SignalWriter + ?Sized> SignalWriter for &mut P {
555    fn set(&mut self, iface: InterfaceNo, ord: Ordinal, bytes: &[u8]) -> Result<(), WriteError> {
556        (**self).set(iface, ord, bytes)
557    }
558    fn invalidate(&mut self, iface: InterfaceNo, ord: Ordinal) -> Result<(), WriteError> {
559        (**self).invalidate(iface, ord)
560    }
561    fn touch(&mut self, iface: InterfaceNo, ord: Ordinal) -> Result<(), WriteError> {
562        (**self).touch(iface, ord)
563    }
564    fn commit(&mut self) {
565        (**self).commit();
566    }
567}
568
569impl<P: EventSource + ?Sized> EventSource for &mut P {
570    fn subscribe(&mut self, iface: InterfaceNo, ords: &[Ordinal]) -> Result<(), SubscribeError> {
571        (**self).subscribe(iface, ords)
572    }
573    fn unsubscribe(&mut self, iface: InterfaceNo, ords: &[Ordinal]) {
574        (**self).unsubscribe(iface, ords);
575    }
576    fn next(&mut self, out: &mut [u8]) -> Result<Option<RawOccurrence>, ReadError> {
577        (**self).next(out)
578    }
579}
580
581impl<P: EventSink + ?Sized> EventSink for &mut P {
582    fn raise(&mut self, iface: InterfaceNo, ord: Ordinal, bytes: &[u8]) -> Result<(), RaiseError> {
583        (**self).raise(iface, ord, bytes)
584    }
585}
586
587impl<P: Caller + ?Sized> Caller for &mut P {
588    fn command(
589        &mut self,
590        iface: InterfaceNo,
591        ord: Ordinal,
592        args: &[u8],
593    ) -> Result<Correlation, SendError> {
594        (**self).command(iface, ord, args)
595    }
596    fn query(
597        &mut self,
598        iface: InterfaceNo,
599        ord: Ordinal,
600        args: &[u8],
601    ) -> Result<Correlation, SendError> {
602        (**self).query(iface, ord, args)
603    }
604    fn ack(&mut self, c: Correlation) -> Option<Result<(), CallError>> {
605        (**self).ack(c)
606    }
607    fn reply(
608        &mut self,
609        c: Correlation,
610        out: &mut [u8],
611    ) -> Result<Option<Result<usize, CallError>>, ReadError> {
612        (**self).reply(c, out)
613    }
614    fn forget(&mut self, c: Correlation) {
615        (**self).forget(c);
616    }
617}
618
619impl<P: Handler + ?Sized> Handler for &mut P {
620    fn serve(&mut self, iface: InterfaceNo, ords: &[Ordinal]) -> Result<(), ServeError> {
621        (**self).serve(iface, ords)
622    }
623    fn next_claim(&mut self, out: &mut [u8]) -> Result<Option<Claim>, ReadError> {
624        (**self).next_claim(out)
625    }
626    fn settle(
627        &mut self,
628        claim: ClaimId,
629        outcome: Result<&[u8], CallError>,
630    ) -> Result<(), SettleError> {
631        (**self).settle(claim, outcome)
632    }
633}
634
635impl<P: FixedReader + ?Sized> FixedReader for &P {
636    fn read_fixed(
637        &self,
638        iface: InterfaceNo,
639        ord: Ordinal,
640        out: &mut [u8],
641    ) -> Result<usize, ReadError> {
642        (**self).read_fixed(iface, ord, out)
643    }
644}
645
646impl<P: FixedReader + ?Sized> FixedReader for &mut P {
647    fn read_fixed(
648        &self,
649        iface: InterfaceNo,
650        ord: Ordinal,
651        out: &mut [u8],
652    ) -> Result<usize, ReadError> {
653        (**self).read_fixed(iface, ord, out)
654    }
655}
656
657impl<P: ScannableSignals + ?Sized> ScannableSignals for &P {
658    fn generation(&self, iface: InterfaceNo) -> u64 {
659        (**self).generation(iface)
660    }
661    fn scan(&self, marks: &mut [Watermark], out: &mut [Changed]) -> usize {
662        (**self).scan(marks, out)
663    }
664}
665
666impl<P: ScannableSignals + ?Sized> ScannableSignals for &mut P {
667    fn generation(&self, iface: InterfaceNo) -> u64 {
668        (**self).generation(iface)
669    }
670    fn scan(&self, marks: &mut [Watermark], out: &mut [Changed]) -> usize {
671        (**self).scan(marks, out)
672    }
673}
674
675impl<P: CoherentSignals + ?Sized> CoherentSignals for &P {
676    fn read_coherent(
677        &self,
678        iface: InterfaceNo,
679        ords: &[Ordinal],
680        out: &mut [u8],
681        samples: &mut [RawSample],
682    ) -> Result<usize, ReadError> {
683        (**self).read_coherent(iface, ords, out, samples)
684    }
685}
686
687impl<P: CoherentSignals + ?Sized> CoherentSignals for &mut P {
688    fn read_coherent(
689        &self,
690        iface: InterfaceNo,
691        ords: &[Ordinal],
692        out: &mut [u8],
693        samples: &mut [RawSample],
694    ) -> Result<usize, ReadError> {
695        (**self).read_coherent(iface, ords, out, samples)
696    }
697}