pub struct TcWriter<M>{ /* 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
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>
 
impl<M> TcWriter<M>
Sourcepub fn new(capacity: usize) -> Self
 
pub fn new(capacity: usize) -> Self
Constructs a new TcWriter<T,D>.
Facilitates mutation of the wrapped T object.
Sourcepub fn apply_change(&self, m: M)
 
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
Sourcepub fn try_apply_change(&self, m: M) -> Result<(), M>
 
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
Sourcepub fn add_reader<T: TakesMessage<M>>(&self, init: T) -> TcReader<T, M>
 
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