Skip to main content

Consumer

Struct Consumer 

Source
pub struct Consumer { /* private fields */ }
Expand description

Cheap read handle over an origin’s broadcast tree.

Clones share the underlying tree state without allocating any per-cursor resources. To actually receive announce / unannounce events, call Self::announced to obtain an AnnounceConsumer.

Implementations§

Source§

impl Consumer

Source

pub fn with_stats(self, session: Session) -> Self

Attach an egress stats context: broadcasts handed out through this handle (and any handle derived from it) are attributed to session on the publisher (egress) side. Pass stats::Session::default to opt out.

Source

pub fn announced(&self) -> AnnounceConsumer

Subscribe to announce / unannounce events for this consumer’s subtree.

Allocates a per-cursor coalescing buffer, registers it with each root in this consumer’s scope, and replays the currently active broadcast set as initial announcements. Drop the returned AnnounceConsumer to unregister.

Source

pub fn consume(&self) -> Self

Returns a cheap duplicate of this read handle.

Source

pub async fn announced_broadcast(&self, path: impl AsPath) -> Option<Consumer>

Block until a broadcast with the given path is announced and return it.

Returns None if the path is outside this consumer’s allowed prefixes or if the consumer is closed before the broadcast is announced. The returned broadcast may itself be closed later. Subscribers should watch broadcast::Consumer::closed to react to that.

Prefer this over Self::request_broadcast when you know the exact path you want but cannot guarantee the announcement has already been received. With moq-lite-05 (and the older Lite01/02) connect() already blocks until the initial announce set lands, so Self::request_broadcast is race-free for broadcasts that were live at connect time; this method is still needed to wait for a broadcast that comes online after connect.

Source

pub fn scope(&self, prefixes: &[Path<'_>]) -> Option<Consumer>

Returns a new Consumer restricted to broadcasts under one of prefixes.

Returns None if there are no legal prefixes (the requested prefixes are disjoint from this consumer’s current scope, so it would always return None).

Source

pub fn request_broadcast(&self, path: impl AsPath) -> Pending<Requesting>

Get a broadcast by path, falling back to a dynamic request when it is not announced.

Returns a kio::Pending future (resolved synchronously for an announced broadcast, otherwise once a handler serves it), mirroring track::Consumer::fetch_group. The lookup order is: an already-announced broadcast resolves immediately; otherwise, if an Dynamic handler is live (see Producer::dynamic), a fallback request is registered and the future resolves when the handler accepts it (or errors if it rejects or every handler drops). Concurrent requests for the same unannounced path coalesce onto one handler request, and once served the broadcast is cached weakly so later requests for that path also share it (rather than re-invoking the handler and opening a duplicate upstream subscription) for as long as it stays live; a closed one is re-served on the next request.

The returned future resolves to Error::Unroutable when the path is not announced and no dynamic handler exists. A request that is registered while a handler is live but then loses every handler before being served also resolves to Error::Unroutable. Unlike an announced broadcast, a dynamically served one is never visible to Self::announced.

Source

pub fn with_root(&self, prefix: impl AsPath) -> Option<Self>

Returns a new Consumer that automatically strips out the provided prefix.

Returns None if the provided root is not authorized; when Self::scope was already used without a wildcard.

Source

pub fn root(&self) -> &Path<'_>

Returns the prefix that is automatically stripped from all paths.

Source

pub fn allowed(&self) -> impl Iterator<Item = &Path<'_>>

Iterate over the path prefixes this handle is permitted to publish or subscribe under.

Source

pub fn absolute(&self, path: impl AsPath) -> Path<'_>

Converts a relative path to an absolute path.

Trait Implementations§

Source§

impl Clone for Consumer

Source§

fn clone(&self) -> Consumer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Consume<Consumer> for Producer

Source§

fn consume(&self) -> Consumer

Derive a read view (a consumer) from this handle.
Source§

impl Consume<Consumer> for Consumer

Source§

fn consume(&self) -> Consumer

Derive a read view (a consumer) from this handle.
Source§

impl Deref for Consumer

Source§

type Target = Origin

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more