Struct trailing_cell::TcWriter
[−]
[src]
pub struct TcWriter<M> where
M: Sync + Clone, { /* fields omitted */ }
A set of connected TcWriter<M>
s have any number (initially 0) of reading
TcWriterT
(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
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
Methods
impl<M> TcWriter<M> where
M: Sync + Clone,
[src]
M: Sync + Clone,
fn new(capacity: usize) -> Self
[src]
Constructs a new TcWriter<T,D>
.
Facilitates mutation of the wrapped T object.
fn apply_change(&self, m: M)
[src]
Broadcasts the given D message to readers. Blocks until there is space
on bus. has the same semantics as underlying bus::Bus::broadcast
fn try_apply_change(&self, m: M) -> Result<(), M>
[src]
Broadcasts the given D message to readers, returns immediately if bus is
full. Has the same semantics as underlying bus::Bus::try_broadcast
fn add_reader<T: TakesMessage<M>>(&self, init: T) -> TcReader<T, M>
[src]
Creates, registers and returns a new reader object to the underlying T
The reader will maintain its own state
Trait Implementations
impl<M> Clone for TcWriter<M> where
M: Sync + Clone,
[src]
M: Sync + Clone,