Struct TVar

Source
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>

Source

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.

Source

pub fn read_clone(&self) -> Stm<T>

Read the value of the TVar as a clone, for subsequent modification. Only call this inside [atomically].

Source

pub fn read(&self) -> Stm<Arc<T>>

Read the value of the TVar. Only call this inside [atomically].

Source

pub fn write(&self, value: T) -> Stm<()>

Replace the value of the TVar. Only call this inside [atomically].

Source

pub fn update<F>(&self, f: F) -> Stm<()>
where F: FnOnce(T) -> T,

Apply an update on the value of the TVar. Only call this inside [atomically].

Source

pub fn update_mut<F>(&self, f: F) -> Stm<()>
where F: FnOnce(&mut T),

Apply an update on the value of the TVar. Only call this inside [atomically].

Source

pub fn modify<F, R>(&self, f: F) -> Stm<R>
where F: FnOnce(T) -> (T, R),

Apply an update on the value of the TVar and return a value. Only call this inside [atomically].

Source

pub fn modify_mut<F, R>(&self, f: F) -> Stm<R>
where F: FnOnce(&mut T) -> R,

Apply an update on the value of the TVar and return a value. Only call this inside [atomically].

Source

pub fn replace(&self, value: T) -> Stm<Arc<T>>

Replace the value of the TVar and return the previous value. Only call this inside [atomically].

Trait Implementations§

Source§

impl<T: Clone> Clone for TVar<T>

Source§

fn clone(&self) -> TVar<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Default for TVar<T>
where T: Any + Sync + Send + Clone + Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for TVar<T>

§

impl<T> !RefUnwindSafe for TVar<T>

§

impl<T> Send for TVar<T>
where T: Send,

§

impl<T> Sync for TVar<T>
where T: Sync,

§

impl<T> Unpin for TVar<T>
where T: Unpin,

§

impl<T> !UnwindSafe for TVar<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.