pub struct StreamCell<T> { /* private fields */ }Expand description
Versioned, thread-safe cell holding the latest value of a stream.
A StreamCell collapses a stream to its most recent value with optimistic
concurrency: each successful write bumps a version counter, and writers must
present the version they observed to commit. It is the shared “current
value” handoff point between a producing stream and its consumers.
§Examples
use sim_lib_stream_combinators::stream_cell;
let cell = stream_cell("first".to_owned());
let snapshot = cell.get().unwrap();
assert_eq!(snapshot.version, 0);
let next = cell.set("second".to_owned(), snapshot.version).unwrap();
assert_eq!(next, 1);
// A stale version is rejected.
assert!(cell.set("third".to_owned(), snapshot.version).is_err());
assert_eq!(cell.get().unwrap().value, "second");Implementations§
Source§impl<T> StreamCell<T>
impl<T> StreamCell<T>
Source§impl<T: Clone> StreamCell<T>
impl<T: Clone> StreamCell<T>
Sourcepub fn get(&self) -> Result<CellSnapshot<T>>
pub fn get(&self) -> Result<CellSnapshot<T>>
Reads a versioned snapshot of the current cell value.
Auto Trait Implementations§
impl<T> !Freeze for StreamCell<T>
impl<T> RefUnwindSafe for StreamCell<T>
impl<T> Send for StreamCell<T>where
T: Send,
impl<T> Sync for StreamCell<T>where
T: Send,
impl<T> Unpin for StreamCell<T>where
T: Unpin,
impl<T> UnsafeUnpin for StreamCell<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for StreamCell<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more