Struct TcWriter

Source
pub struct TcWriter<M>
where M: Sync + Clone,
{ /* private fields */ }
Expand description

A set of connected TcWriter<M>s have any number (initially 0) of reading TcWriter<T,M> objects for any types T (typically the same type T). The data within some reader r can be then accessed by dereferencing *r.

This is particularly useful when: - The data has the set of writers W and readers R, where W != R - The speed of reads is more vital than the speed of writes. eg: Writes are very rare - Its OK if read states are slightly stale

It also has with it the nice properties of: - Granular control of reader-synchronization events - joining and leaving of writers whenever (using TcWriter::clone) - joining and leaving of readers whenever (using TcWriter::add_reader) - both blocking and non-blocking write options - a reader can be unwrapped to return their T state.

The implementation allows readers to be initialized with not only different local states, but even initial states of different types, (so long as they all implement TakesMessage for the same M as the writer(s)). It’s not clear to me how this option might be useful, but it costs nothing to support, so why not.

TcWriter is implemented as a wrapper over a bus::Bus, with ‘write’ messages being broadcast to all readers, and readers explicitly accepting messages and applying them to their local T state.

See the tests for some commented examples

Implementations§

Source§

impl<M> TcWriter<M>
where M: Sync + Clone,

Source

pub fn new(capacity: usize) -> Self

Constructs a new TcWriter<T,D>. Facilitates mutation of the wrapped T object.

Source

pub fn apply_change(&self, m: M)

Broadcasts the given D message to readers. Blocks until there is space on bus. has the same semantics as underlying bus::Bus::broadcast

Source

pub fn try_apply_change(&self, m: M) -> Result<(), M>

Broadcasts the given D message to readers, returns immediately if bus is full. Has the same semantics as underlying bus::Bus::try_broadcast

Source

pub fn add_reader<T: TakesMessage<M>>(&self, init: T) -> TcReader<T, M>

Creates, registers and returns a new reader object to the underlying T The reader will maintain its own state

Trait Implementations§

Source§

impl<M> Clone for TcWriter<M>
where M: Sync + Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<M> Freeze for TcWriter<M>

§

impl<M> RefUnwindSafe for TcWriter<M>

§

impl<M> Send for TcWriter<M>
where M: Send,

§

impl<M> Sync for TcWriter<M>
where M: Send,

§

impl<M> Unpin for TcWriter<M>

§

impl<M> UnwindSafe for TcWriter<M>

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