[][src]Struct contrail::Value

pub struct Value<M, T> { /* fields omitted */ }

A reference to a value stored on the trail.

The type parameter T is the type of value stored on the trail, and the type parameter M represents how the value is stored on the trail. A Value<Backtrackable, T> is stored on the trail in backtrackable memory, whereas a Value<NonBacktrackable, T> is stored on the trail in non-backtrackable memory.

Instead of using Value directly, it's often easier to use the type definitions BacktrackableValue and NonBacktrackableValue.

Methods

impl<M, T> Value<M, T> where
    M: StorageMode,
    T: Bytes
[src]

pub fn new(builder: &mut TrailBuilder, val: T) -> Self[src]

Creates a new Value with the given value.

The Value is usable after the TrailBuilder used to create it is finished.

Examples

use contrail::{BacktrackableValue, TrailBuilder};

let mut builder = TrailBuilder::new();
let value = BacktrackableValue::new(&mut builder, 'b');
let trail = builder.finish();

// the value is usable now
assert_eq!(value.get(&trail), 'b');

pub fn get(self, trail: &Trail) -> T[src]

Gets the value from the trail.

Examples

use contrail::{BacktrackableValue, TrailBuilder};

let mut builder = TrailBuilder::new();
let value = BacktrackableValue::new(&mut builder, 5);
let mut trail = builder.finish();

assert_eq!(value.get(&trail), 5);

pub fn set(self, trail: &mut Trail, new_val: T)[src]

Sets the value on the trail.

Examples

use contrail::{BacktrackableValue, TrailBuilder};

let mut builder = TrailBuilder::new();
let value = BacktrackableValue::new(&mut builder, 5);
let mut trail = builder.finish();

value.set(&mut trail, 42);
assert_eq!(value.get(&trail), 42);

pub fn update(self, trail: &mut Trail, f: impl FnOnce(T) -> T)[src]

Updates the value on the trail using the given function.

Examples

use contrail::{BacktrackableValue, TrailBuilder};

let mut builder = TrailBuilder::new();
let value = BacktrackableValue::new(&mut builder, 5);
let mut trail = builder.finish();

value.update(&mut trail, |x| x * x);
assert_eq!(value.get(&trail), 25);

Trait Implementations

impl<M, T> Clone for Value<M, T>[src]

impl<M, T> Copy for Value<M, T>[src]

impl<M, T> Debug for Value<M, T> where
    M: StorageMode
[src]

impl<M, T> Eq for Value<M, T>[src]

impl<M, T> PartialEq<Value<M, T>> for Value<M, T>[src]

Auto Trait Implementations

impl<M, T> RefUnwindSafe for Value<M, T> where
    M: RefUnwindSafe,
    T: RefUnwindSafe

impl<M, T> Send for Value<M, T> where
    M: Send,
    T: Send

impl<M, T> Sync for Value<M, T> where
    M: Sync,
    T: Sync

impl<M, T> Unpin for Value<M, T> where
    M: Unpin,
    T: Unpin

impl<M, T> UnwindSafe for Value<M, T> where
    M: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.