[][src]Struct contrail::Array

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

A reference to a fixed-length array of values 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. An Array<Backtrackable, T> is stored on the trail in backtrackable memory, whereas an Array<NonBacktrackable, T> is stored on the trail in non-backtrackable memory.

Instead of using Array directly, it's often easier to use the type definitions BacktrackableArray and NonBacktrackableArray.

Methods

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

pub fn new(
    builder: &mut TrailBuilder,
    vals: impl IntoIterator<Item = T>
) -> Self
[src]

Creates a new Array with the given values.

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

Examples

use contrail::{BacktrackableArray, TrailBuilder};

let mut builder = TrailBuilder::new();
let array = BacktrackableArray::new(&mut builder, 5..10);
let trail = builder.finish();

// the array is usable now
assert_eq!(array.get(&trail, 2), 7);

pub fn len(&self) -> usize[src]

Returns the length of the array.

Examples

use contrail::{BacktrackableArray, TrailBuilder};

let mut builder = TrailBuilder::new();
let array = BacktrackableArray::new(&mut builder, 0..8);

assert_eq!(array.len(), 8);

pub fn is_empty(&self) -> bool[src]

Checks if the length of the array is equal to 0.

Examples

use contrail::{BacktrackableArray, TrailBuilder};

let mut builder = TrailBuilder::new();
let empty = BacktrackableArray::new(&mut builder, 0..0);
let not_empty = BacktrackableArray::new(&mut builder, 0..1);

assert_eq!(empty.is_empty(), true);
assert_eq!(not_empty.is_empty(), false);

Important traits for ArrayIter<'t, M, T>
pub fn iter<'t>(&self, trail: &'t Trail) -> ArrayIter<'t, M, T>[src]

Returns an iterator over the elements of the array.

Examples

use contrail::{BacktrackableArray, TrailBuilder};

let mut builder = TrailBuilder::new();
let odds = BacktrackableArray::new(&mut builder, (0..10).map(|x| 2 * x + 1));
let trail = builder.finish();

for odd in odds.iter(&trail) {
    assert_eq!(odd % 2, 1);
}

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

Gets the value of the array at the given index.

Panics

Panics if the index is out of bounds.

Examples

use contrail::{BacktrackableArray, Trail, TrailBuilder};

let mut builder = TrailBuilder::new();
let array = BacktrackableArray::new(&mut builder, 0..10);
let mut trail = builder.finish();

assert_eq!(array.get(&trail, 4), 4);

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

Sets the value of the array at the given index.

Panics

Panics if the index is out of bounds.

Examples

use contrail::{BacktrackableArray, Trail, TrailBuilder};

let mut builder = TrailBuilder::new();
let array = BacktrackableArray::new(&mut builder, 0..10);
let mut trail = builder.finish();

assert_eq!(array.get(&trail, 4), 4);

array.set(&mut trail, 4, -23);
assert_eq!(array.get(&trail, 4), -23);

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

Updates the value of the array at the given index using the given update function.

Panics

Panics if the index is out of bounds.

Examples

use contrail::{BacktrackableArray, Trail, TrailBuilder};

let mut builder = TrailBuilder::new();
let array = BacktrackableArray::new(&mut builder, 0..10);
let mut trail = builder.finish();

assert_eq!(array.get(&trail, 4), 4);

array.update(&mut trail, 4, |x| x * x);
assert_eq!(array.get(&trail, 4), 16);

pub fn swap(&self, trail: &mut Trail, i: usize, j: usize)[src]

Swaps the two values at the given indices of the array in memory.

Panics

Panics if either of the indices are out of bounds.

Examples

use contrail::{BacktrackableArray, TrailBuilder};

let mut builder = TrailBuilder::new();
let array = BacktrackableArray::new(&mut builder, vec!['r', 'u', 't', 's']);
let mut trail = builder.finish();

assert_eq!(array.get(&trail, 2), 't');
assert_eq!(array.get(&trail, 3), 's');

array.swap(&mut trail, 2, 3);

assert_eq!(array.get(&trail, 2), 's');
assert_eq!(array.get(&trail, 3), 't');

Trait Implementations

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

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

This method tests for !=.

impl<M, T> Clone for Array<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 Array<M, T>[src]

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

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

Auto Trait Implementations

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

impl<M, T> Sync for Array<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> Any for T where
    T: 'static + ?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.