pub trait Write<T> where
    T: Clone
{ fn get_mut<'a>(&'a self, var: &'a RLUVar<T>) -> Result<WriteGuard<'a, T>>; }
Expand description

Write<T> gives mutable access to synchronized value via the current managing context.

Required Methods

Returns an mutable WriteGuard on the value of RLUVar

This function returns a mutable copy if the original value. The WriteGuard ensures that after dereferencing and writing to the value, the internal log will be updated to the most recent change

Example
use stronghold_rlu::*;

// create simple value, that should be managed by RLU
let value = 6usize;

// first we need to create a controller
let ctrl = RLU::new();

// via the controller  we create a RLUVar reference
let rlu_var: RLUVar<usize> = ctrl.create(value);

// we clone the reference to it to use it inside a thread
let var_1 = rlu_var.clone();

// via the controller we can spawn a thread safe context
ctrl.execute(move |mut context| {
    let mut inner = context.get_mut(&var_1)?;
    let data = &mut *inner;
    *data += 10;
    Ok(())
});

assert_eq!(rlu_var.get(), 16);

Implementors