[−][src]Struct swym::thread_key::ThreadKey
A handle to swym
's thread local state.
ThreadKey
can be acquired by calling get
.
ThreadKey
's encapsulate the state required to perform transactions, and provides the necessary
methods for running transactions.
Methods
impl ThreadKey
[src]
pub fn read<'tcell, F, O>(&'tcell self, f: F) -> O where
F: FnMut(&ReadTx<'tcell>) -> Result<O, Error>,
[src]
F: FnMut(&ReadTx<'tcell>) -> Result<O, Error>,
Performs a transaction capabable of only reading.
Examples
use swym::{tcell::TCell, thread_key}; let x = TCell::new(String::from("not gonna be overwritten")); let thread_key = thread_key::get(); let x_clone = thread_key.read(|tx| Ok(x.borrow(tx, Default::default())?.to_owned())); assert_eq!(x_clone, "not gonna be overwritten");
pub fn rw<'tcell, F, O>(&'tcell self, f: F) -> O where
F: FnMut(&mut RWTx<'tcell>) -> Result<O, Error>,
[src]
F: FnMut(&mut RWTx<'tcell>) -> Result<O, Error>,
Performs a transaction capabable of reading and writing.
Panics
Panics if there is already a running transaction.
Examples
use swym::{tcell::TCell, thread_key}; let x = TCell::new(String::from("gonna be overwritten")); let thread_key = thread_key::get(); let prev_x = thread_key.rw(|tx| { let r = x.borrow(tx, Default::default())?.to_owned(); x.set(tx, "overwritten".to_owned())?; Ok(r) }); assert_eq!(prev_x, "gonna be overwritten");
pub fn try_read<'tcell, F, O>(&'tcell self, f: F) -> Result<O, TryReadErr> where
F: FnMut(&ReadTx<'tcell>) -> Result<O, Error>,
[src]
F: FnMut(&ReadTx<'tcell>) -> Result<O, Error>,
Performs a transaction capabable of only reading.
Errors
Returns a TryReadErr
if a transaction is already running on the current thread.
Examples
use swym::{tcell::TCell, thread_key}; let x = TCell::new(String::from("not gonna be overwritten")); let thread_key = thread_key::get(); let x_clone = thread_key .try_read(|tx| Ok(x.borrow(tx, Default::default())?.to_owned())) .unwrap(); assert_eq!(x_clone, "not gonna be overwritten");
pub fn try_rw<'tcell, F, O>(&'tcell self, f: F) -> Result<O, TryRWErr> where
F: FnMut(&mut RWTx<'tcell>) -> Result<O, Error>,
[src]
F: FnMut(&mut RWTx<'tcell>) -> Result<O, Error>,
Performs a transaction capabable of reading and writing.
Errors
Returns a TryRWErr
if a transaction is already running on the current thread.
Examples
use swym::{tcell::TCell, thread_key}; let x = TCell::new(String::from("gonna be overwritten")); let thread_key = thread_key::get(); let prev_x = thread_key .try_rw(|tx| { let prev_x = x.borrow(tx, Default::default())?.to_owned(); x.set(tx, "overwritten".to_owned())?; Ok(prev_x) }) .unwrap(); assert_eq!(prev_x, "gonna be overwritten");
pub unsafe fn read_unchecked<'tcell, F, O>(&'tcell self, f: F) -> O where
F: FnMut(&ReadTx<'tcell>) -> Result<O, Error>,
[src]
F: FnMut(&ReadTx<'tcell>) -> Result<O, Error>,
Performs a transaction capabable of only reading.
Safety
If the thread is currently in a transaction, this results in undefined behavior.
Examples
use swym::{tcell::TCell, thread_key}; let x = TCell::new(String::from("not gonna be overwritten")); let thread_key = thread_key::get(); unsafe { let x_clone = thread_key.read_unchecked(|tx| Ok(x.borrow(tx, Default::default())?.to_owned())); assert_eq!(x_clone, "not gonna be overwritten"); }
pub unsafe fn rw_unchecked<'tcell, F, O>(&'tcell self, f: F) -> O where
F: FnMut(&mut RWTx<'tcell>) -> Result<O, Error>,
[src]
F: FnMut(&mut RWTx<'tcell>) -> Result<O, Error>,
Performs a transaction capabable of reading and writing.
Safety
If the thread is currently in a transaction, this results in undefined behavior.
Examples
use swym::{tcell::TCell, thread_key}; let x = TCell::new(String::from("gonna be overwritten")); let thread_key = thread_key::get(); unsafe { let prev_x = thread_key.rw_unchecked(|tx| { let prev_x = x.borrow(tx, Default::default())?.to_owned(); x.set(tx, "overwritten".to_owned())?; Ok(prev_x) }); assert_eq!(prev_x, "gonna be overwritten"); }
Trait Implementations
impl Clone for ThreadKey
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Drop for ThreadKey
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,