[−][src]Struct contrail::Array
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]
M: StorageMode,
T: Bytes,
pub fn new(
builder: &mut TrailBuilder,
vals: impl IntoIterator<Item = T>
) -> Self
[src]
builder: &mut TrailBuilder,
vals: impl IntoIterator<Item = T>
) -> Self
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);
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> Clone for Array<M, T>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<M, T> Copy for Array<M, T>
[src]
impl<M, T> Debug for Array<M, T> where
M: StorageMode,
[src]
M: StorageMode,
impl<M, T> Eq for Array<M, T>
[src]
impl<M, T> PartialEq<Array<M, T>> for Array<M, T>
[src]
Auto Trait Implementations
impl<M, T> RefUnwindSafe for Array<M, T> where
M: RefUnwindSafe,
T: RefUnwindSafe,
M: RefUnwindSafe,
T: RefUnwindSafe,
impl<M, T> Send for Array<M, T> where
M: Send,
T: Send,
M: Send,
T: Send,
impl<M, T> Sync for Array<M, T> where
M: Sync,
T: Sync,
M: Sync,
T: Sync,
impl<M, T> Unpin for Array<M, T> where
M: Unpin,
T: Unpin,
M: Unpin,
T: Unpin,
impl<M, T> UnwindSafe for Array<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>,