[][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> PartialEq<Value<M, T>> for Value<M, T>[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<M, T> Eq 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]

Auto Trait Implementations

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

Blanket Implementations

impl<T> From for T[src]

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

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

type Owned = T

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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