pub struct TVar<T> { /* private fields */ }Expand description
TVar is the public interface to lift data into the transactional
context for subsequent read and write operations.
TVar is our handle to a variable, but reading and writing go through a transaction.
It also tracks which threads are waiting on it.
Implementations§
source§impl<T: Any + Sync + Send + Clone> TVar<T>
impl<T: Any + Sync + Send + Clone> TVar<T>
sourcepub fn new(value: T) -> TVar<T>
pub fn new(value: T) -> TVar<T>
Create a new TVar. The initial version is 0, so that if a
TVar is created in the middle of a transaction it will
not cause any MVCC conflict during the commit.
sourcepub fn read_clone(&self) -> StmResult<T>
pub fn read_clone(&self) -> StmResult<T>
Read the value of the TVar as a clone, for subsequent modification. Only call this inside atomically.
sourcepub fn read(&self) -> StmResult<Arc<T>>
pub fn read(&self) -> StmResult<Arc<T>>
Read the value of the TVar. Only call this inside atomically.
sourcepub fn write(&self, value: T) -> StmResult<()>
pub fn write(&self, value: T) -> StmResult<()>
Replace the value of the TVar. Only call this inside atomically.
sourcepub fn update<F>(&self, f: F) -> StmResult<()>where
F: FnOnce(T) -> T,
pub fn update<F>(&self, f: F) -> StmResult<()>where F: FnOnce(T) -> T,
Apply an update on the value of the TVar. Only call this inside atomically.