Struct stm::TVar
[−]
[src]
pub struct TVar<T> { /* fields omitted */ }
A variable that can be used in a STM-Block
Methods
impl<T> TVar<T> where
T: Any + Sync + Send + Clone,
[src]
T: Any + Sync + Send + Clone,
fn new(val: T) -> TVar<T>
Create a new TVar
.
fn read_atomic(&self) -> T
read_atomic
reads a value atomically, without starting a transaction.
It is semantically equivalent to
use stm::*; let var = TVar::new(0); atomically(|trans| var.read(trans));
but more efficient.
read_atomic
returns a clone of the value.
fn read_ref_atomic(&self) -> Arc<Any + Send + Sync>
Read a value atomically but return a reference.
This is mostly used internally, but can be useful in
some cases, because read_atomic
performs clones the
value, which may be expensive.
fn read(&self, transaction: &mut Transaction) -> StmResult<T>
The normal way to access a var.
It is equivalent to transaction.read(&var)
, but more
convenient.
fn write(&self, transaction: &mut Transaction, value: T) -> StmResult<()>
The normal way to write a var.
It is equivalent to transaction.write(&var, value)
, but more
convenient.
fn modify<F>(&self, transaction: &mut Transaction, f: F) -> StmResult<()> where
F: FnOnce(T) -> T,
F: FnOnce(T) -> T,
Modify the content of a TVar
with the function f.
use stm::*; let var = TVar::new(21); atomically(|trans| var.modify(trans, |x| x*2) ); assert_eq!(var.read_atomic(), 42);
fn replace(&self, transaction: &mut Transaction, value: T) -> StmResult<T>
Replaces the value of a TVar
with a new one, returning
the old one.
use stm::*; let var = TVar::new(0); let x = atomically(|trans| var.replace(trans, 42) ); assert_eq!(x, 0); assert_eq!(var.read_atomic(), 42);
fn control_block(&self) -> &Arc<VarControlBlock>
Access the control block of the var.
Internal use only!
Trait Implementations
impl<T: Clone> Clone for TVar<T>
[src]
fn clone(&self) -> TVar<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more