Skip to main content

Producer

Struct Producer 

Source
pub struct Producer<T> { /* private fields */ }
Expand description

Publishes a JSON value over a track, choosing snapshots and deltas automatically.

An Encoder that owns its track: it writes each encoded frame and rolls a group whenever the encoder emits a snapshot. When something else already owns the track, use the Encoder directly.

Cheaply clonable: clones share one underlying track and publishing state, like other MoQ producers.

Implementations§

Source§

impl<T> Producer<T>

Source

pub fn consume(&self) -> Subscriber

Create a subscriber for the underlying track.

Source

pub fn is_used(&self) -> bool

Whether any consumer for the underlying track currently exists.

The demand signal for a producer serving on request: an unused track is cached state nobody is watching, safe to drop and recreate on the next request.

Source§

impl<T: Serialize> Producer<T>

Source

pub fn new(track: Producer, config: ProducerConfig) -> Self

Create a producer that publishes to the given track.

Source

pub fn update(&mut self, value: &T) -> Result<()>

Publish a new value, emitting a snapshot or a delta automatically.

Does nothing if the value is unchanged from the previous publish.

Source

pub fn lock(&mut self) -> Guard<'_, T>

Lock the current value for in-place editing, publishing on drop.

The returned Guard derefs to the current value: everything published through this producer so far, composed, or T::default() if nothing has been. Editing it through DerefMut marks the guard dirty; when a dirty guard drops it publishes the result, a no-op if unchanged.

After a rejected frame the current value is what the producer last tried to publish, which consumers never received. That is deliberate. The guard exists so independent owners can each edit their own field without clobbering, and dropping a rejected owner’s field would clobber it for whoever edits next, which is the failure this API exists to prevent. The owner whose write failed sees the error and can act on it; the next successful publish is a full snapshot carrying the composed value, so consumers converge on it either way.

This is the counterpart to a callback: hold the guard, mutate, drop. The guard holds the producer’s lock for its lifetime, so independent owners are serialized: each one starts from the latest value and their changes compose instead of clobbering. Don’t hold a guard across an .await, since that keeps the lock held while suspended.

Publishing on drop can fail (a closed track, a value that won’t serialize) and only logs a warning. Call Guard::commit instead to handle the error.

Source

pub fn finish(&mut self) -> Result<()>

Finish the track, closing any open group.

Trait Implementations§

Source§

impl<T> Clone for Producer<T>

Source§

fn clone(&self) -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for Producer<T>

§

impl<T> RefUnwindSafe for Producer<T>

§

impl<T> Send for Producer<T>

§

impl<T> Sync for Producer<T>

§

impl<T> Unpin for Producer<T>

§

impl<T> UnsafeUnpin for Producer<T>

§

impl<T> UnwindSafe for Producer<T>

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<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