[−][src]Struct contrail::Value
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]
M: StorageMode,
T: Bytes,
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]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<M, T> Copy for Value<M, T>
[src]
impl<M, T> Debug for Value<M, T> where
M: StorageMode,
[src]
M: StorageMode,
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,
M: RefUnwindSafe,
T: RefUnwindSafe,
impl<M, T> Send for Value<M, T> where
M: Send,
T: Send,
M: Send,
T: Send,
impl<M, T> Sync for Value<M, T> where
M: Sync,
T: Sync,
M: Sync,
T: Sync,
impl<M, T> Unpin for Value<M, T> where
M: Unpin,
T: Unpin,
M: Unpin,
T: Unpin,
impl<M, T> UnwindSafe for Value<M, T> where
M: UnwindSafe,
T: UnwindSafe,
M: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,