Skip to main content

Producer

Struct Producer 

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

Publishes an ordered log of JSON records over a track, one record per frame in a single group.

An Encoder that owns its track. When something else already owns the track, use the Encoder directly.

Cheaply clonable: clones share one underlying track and publishing state, so multiple owners (e.g. several producers feeding one log) append into a single ordered stream.

finish or abort a complete or failed log. Dropping the last clone unfinished closes the track cleanly while nobody reads it, so an on-demand publisher drops it once its demand goes idle. Once it published, a reader still reading reads [moq_net::Error::Dropped] instead of being handed to the track’s next producer, which could not continue the log (see [moq_net::track::Producer::abandon]).

Implementations§

Source§

impl<T> Producer<T>

Source

pub fn consume(&self) -> Subscriber

Create a subscriber for the underlying track.

Still hands one back once a failed write has ended the log: the subscriber surfaces the abort on its first read, which is what tells a late reader the log is truncated.

Source

pub fn demand(&self) -> Demand

A watch-only handle to the underlying track’s subscriber demand.

Weak, so holding it neither keeps the track open nor contends with publishing.

Source§

impl<T: Serialize> Producer<T>

Source

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

Create a producer that publishes to the given track.

Source

pub fn append(&mut self, value: &T, at: Timestamp) -> Result<usize>

Append one record to the log at at (see Timed::at).

The log accepts appends for its track’s life. A record larger than a frame may be is refused with [moq_net::Error::FrameTooLarge] before anything is written, leaving the log intact. A timestamp that doesn’t match the track’s timescale (unscaled on a timed track, scaled on a scale-less one, or beyond what its scale can hold) is refused with [moq_net::Error::TimestampMismatch] the same way, so a corrected append carries on.

Any other failure ends the track. A log missing a record is not the lossless log a stream promises, and that holds whether the group rejected the record or it never encoded at all, so the failure is surfaced rather than papered over with a second group. The track is aborted rather than closed cleanly, so a consumer sees the failure instead of a log that merely looks complete. Every later append fails on the ended track.

Returns the encoded size of the frame written.

Source

pub fn finish(self) -> Result<Finished<T>>

Finish the track, closing the group, and return the Finished log.

Clones sharing the track see it ended: their next append fails.

Source

pub fn abort(self, err: Error) -> Result<()>

Abort the track with the given error, which consumers see in place of a clean end.

Consumes the handle, since nothing can be appended afterwards. Clones sharing the track see it closed: their next append fails.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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