Skip to main content

ValueWriter

Struct ValueWriter 

pub struct ValueWriter<T>
where T: Serialize,
{ /* private fields */ }
Expand description

Writes a latest-value JSON track, stamping each update with the time it is made.

Each update gets the moq clock’s time, Timestamp::from(Instant::now()) at the track’s timescale, or one tick after the previous stamp if the clock has not moved past it. A tick is a millisecond on a track that counts milliseconds, as the tracks iroh-live creates do. The stamps strictly increase, as the track’s group starts must, so a burst of updates within one millisecond runs a few milliseconds ahead of the clock and meets it again once the updates slow down.

The track must be timed: on a track without a timescale, every update fails with moq_net::Error::TimestampMismatch.

Clones share the track and the stamps, and each update stamps and writes under one lock, so clones on several threads cannot reorder their stamps. The last clone to drop finishes the track, so readers see it end.

Implementations§

§

impl<T> ValueWriter<T>
where T: Serialize,

pub fn new(track: Producer, config: Config) -> ValueWriter<T>

Creates a writer that publishes to track.

The track must be timed, and nothing else should write to it.

pub fn update(&self, value: &T) -> Result<Option<usize>, ValueError>

Publishes value, stamped now.

Returns the encoded size of the frame written, or None if value equals the current value and nothing was written.

§Errors

Fails with moq_net::Error::Closed once the track is finished, with moq_net::Error::TimestampMismatch on an untimed track, and with any error of snapshot::Producer::update.

pub fn update_at( &self, value: &T, at: Timestamp, ) -> Result<Option<usize>, ValueError>

Publishes value at at, a time the caller chose.

The caller owns the order: an at that starts a group at or before the previous group fails with moq_net::Error::TimestampMismatch. A later update stamps after at.

§Errors

As update, and fails with moq_net::Error::TimestampMismatch for an at the track cannot take.

pub fn mutate(&self, edit: impl FnOnce(&mut T)) -> Result<(), ValueError>

Edits the current value in place and publishes it, stamped now.

The closure receives the current value: everything published so far, or T::default() if nothing has been. An unchanged value publishes nothing. See snapshot::Producer::mutate.

§Errors

As update, and fails if the current value does not deserialize as T.

pub fn finish(self) -> Result<(), ValueError>

Finishes the track, so readers see it end.

Clones then fail to update with moq_net::Error::Closed. Dropping the last clone finishes the track too, so call this only to see the error or to end the track while clones remain.

§Errors

Fails if the track was aborted, or if finishing it fails.

pub fn producer(&self) -> Producer<T>

Returns the moq-json producer, for poll_refresh, cut or consume.

It shares the track with the writer: a write through it bypasses the stamps, and the writer’s last clone finishes the track for it too.

Trait Implementations§

§

impl<T> Clone for ValueWriter<T>
where T: Serialize,

§

fn clone(&self) -> ValueWriter<T>

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
§

impl<T> Debug for ValueWriter<T>
where T: Serialize,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ValueWriter<T>

§

impl<T> RefUnwindSafe for ValueWriter<T>

§

impl<T> Send for ValueWriter<T>

§

impl<T> Sync for ValueWriter<T>

§

impl<T> Unpin for ValueWriter<T>

§

impl<T> UnsafeUnpin for ValueWriter<T>

§

impl<T> UnwindSafe for ValueWriter<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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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

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