[][src]Struct indexing::container::Container

pub struct Container<'id, Array, Mode = ()> { /* fields omitted */ }

A branded container, that allows access only to indices and ranges with the exact same brand in the 'id parameter.

The elements in the underlying data structure are accessible partly through special purpose methods, and through indexing/slicing.

The Container can be indexed like self[i] where i is a trusted dereferenceable index or range, and equivalently using &self[i..] or &self[..i] where i is a trusted index. Indexing like this uses no runtime bounds checking at all, and it statically guaranteed to be in bounds.

The container can also be sliced for its complete range: &self[..].

Methods

impl<'id, Array, T, Mode> Container<'id, Array, Mode> where
    Array: Trustworthy<Item = T>, 
[src]

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

pub fn only_index(self) -> Container<'id, Array, OnlyIndex>[src]

Convert the container into an only-indexing container.

The container no longer allows pointer access. This unlocks some features.

pub fn empty_range(&self) -> Range<'id>[src]

Return the range [0, 0)

pub fn range(&self) -> Range<'id>[src]

Return the full range of the Container.

pub fn vet(&self, index: usize) -> Result<Index<'id>, IndexingError>[src]

Vet the absolute index.

pub fn vet_range(&self, r: Range<usize>) -> Result<Range<'id>, IndexingError>[src]

Vet the range r.

pub fn split_at<P>(&self, index: Index<'id, P>) -> (Range<'id>, Range<'id, P>)[src]

pub fn split_after(
    &self,
    index: Index<'id>
) -> (Range<'id, NonEmpty>, Range<'id>)
[src]

Split in two ranges, where the first includes the index and the second starts with the following index.

pub fn split_around<P>(&self, r: Range<'id, P>) -> (Range<'id>, Range<'id>)[src]

Split around the Range r: Return ranges corresponding to 0..r.start and r.end...

So that input r and return values (s, t) cover the whole container in the order s, r, t.

pub fn before<P>(&self, index: Index<'id, P>) -> Range<'id>[src]

Return the range before (not including) the index itself

pub fn after(&self, index: Index<'id>) -> Range<'id>[src]

Return the range after (not including) the index itself

pub fn range_of<P, R>(&self, r: R) -> Range<'id> where
    R: OnePointRange<Index<'id, P>>, 
[src]

pub fn forward(&self, index: &mut Index<'id>) -> bool[src]

Increment index, if doing so would still be in bounds.

Return true if the index was incremented.

pub fn forward_by(&self, index: &mut Index<'id>, offset: usize) -> bool[src]

Increment index, if doing so would still be in bounds.

Return true if the index was incremented.

pub fn forward_range_by<P>(&self, r: Range<'id, P>, offset: usize) -> Range<'id>[src]

Increment r, clamping to the end of the Container.

pub fn backward(&self, index: &mut Index<'id>) -> bool[src]

Decrement index, if doing so would still be in bounds.

Return true if the index was decremented.

pub fn scan_from<'b, F>(
    &'b self,
    index: Index<'id>,
    f: F
) -> Range<'id, NonEmpty> where
    F: FnMut(&'b T) -> bool,
    T: 'b,
    Array: Contiguous<Item = T>, 
[src]

Examine the elements after index in order from lower indices towards higher. While the closure returns true, continue scan and include the scanned element in the range.

Result always includes index in the range

pub fn scan_from_rev<'b, F>(
    &'b self,
    index: Index<'id>,
    f: F
) -> Range<'id, NonEmpty> where
    F: FnMut(&'b T) -> bool,
    T: 'b,
    Array: Contiguous<Item = T>, 
[src]

Examine the elements before index in order from higher indices towards lower. While the closure returns true, continue scan and include the scanned element in the range.

Result always includes index in the range.

pub fn scan_range<'b, F, P>(
    &'b self,
    range: Range<'id, P>,
    f: F
) -> (Range<'id>, Range<'id>) where
    F: FnMut(&'b T) -> bool,
    T: 'b,
    Array: Contiguous<Item = T>, 
[src]

Examine the elements range in order from lower indices towards higher. While the closure returns true, continue scan and include the scanned element in the range.

pub fn swap(&mut self, i: Index<'id>, j: Index<'id>) where
    Array: GetUncheckedMut
[src]

Swap elements at i and j (they may be equal).

pub fn rotate1_up<R>(&mut self, r: R) where
    Array: Contiguous + GetUncheckedMut,
    R: IntoCheckedRange<'id>, 
[src]

Rotate elements in the range r by one step to the right (towards higher indices)

pub fn rotate1_down<R>(&mut self, r: R) where
    Array: Contiguous + GetUncheckedMut,
    R: IntoCheckedRange<'id>, 
[src]

Rotate elements in the range r by one step to the left (towards lower indices)

pub fn index_twice<P, Q>(
    &mut self,
    r: Range<'id, P>,
    s: Range<'id, Q>
) -> Result<(&mut [T], &mut [T]), IndexingError> where
    Array: ContiguousMut
[src]

Index by two nonoverlapping ranges, where r is before s.

pub fn zip_mut_raw<P, Q, F>(&mut self, r: Range<'id, P>, s: Range<'id, Q>, f: F) where
    F: FnMut(*mut T, *mut T),
    Array: GetUncheckedMut
[src]

Zip by raw pointer (will be indentical if ranges have same starting point)

impl<'id, Array, T> Container<'id, Array, OnlyIndex> where
    Array: Pushable<Item = T>, 
[src]

Methods specific to only index mode

pub fn push(&mut self, element: T) -> Index<'id>[src]

Add one element to the underlying storage, and return its index.

All outstanding indices remain valid, only the length of the container is now larger.

pub fn insert<Q>(&mut self, index: Index<'id, Q>, element: T)[src]

Insert one element in the underlying storage at index.

All outstanding indices remain valid (in bounds), but elements have shifted.

impl<'id, Array, T, Mode> Container<'id, Array, Mode> where
    Array: Trustworthy<Item = T> + FixedLength
[src]

pub fn make_twin<Array2>(
    &self,
    arr: Array2
) -> Result<Container<'id, Array2, OnlyIndex>, IndexingError> where
    Array2: Trustworthy + FixedLength
[src]

Create a twin Container, that admits the same branded indices as self

Checks the compatibilty (length) of both arrays and returns the twin container if it is admissible.

The twin container is OnlyIndex-marked, because only indices/index ranges transfer between twins, and branded raw pointers of course not.

Trait Implementations

impl<'id, Array, Mode> Clone for Container<'id, Array, Mode> where
    Array: Clone + FixedLength
[src]

A container can be cloned if the inner array can (typically a shared slice).

But containers of vectors can not be cloned:

This example deliberately fails to compile
use indexing::scope;
scope(vec![0; 10], |v| {
    let _u = v.clone();
});

impl<'id, Array, M> Index<Index<'id, NonEmpty>> for Container<'id, Array, M> where
    Array: GetUnchecked
[src]

&self[i] where i is an Index<'id>.

type Output = Array::Item

The returned type after indexing.

impl<'id, T, Array, P, M> Index<Range<'id, P>> for Container<'id, Array, M> where
    Array: Contiguous<Item = T>, 
[src]

&self[r] where r is a Range<'id>.

type Output = [T]

The returned type after indexing.

impl<'id, T, P, Array, M> Index<RangeFrom<Index<'id, P>>> for Container<'id, Array, M> where
    Array: Contiguous<Item = T>, 
[src]

&self[i..] where i is an Index<'id, P> which may be an edge index.

type Output = [T]

The returned type after indexing.

impl<'id, T, P, Array, M> Index<RangeTo<Index<'id, P>>> for Container<'id, Array, M> where
    Array: Contiguous<Item = T>, 
[src]

&self[..i] where i is an Index<'id, P>, which may be an edge index.

type Output = [T]

The returned type after indexing.

impl<'id, T, Array, M> Index<RangeFull> for Container<'id, Array, M> where
    Array: Contiguous<Item = T>, 
[src]

&self[..]

type Output = [T]

The returned type after indexing.

impl<'id, Array, M> IndexMut<Index<'id, NonEmpty>> for Container<'id, Array, M> where
    Array: GetUncheckedMut
[src]

&mut self[i] where i is an Index<'id>.

impl<'id, Array, P, M> IndexMut<Range<'id, P>> for Container<'id, Array, M> where
    Array: ContiguousMut
[src]

&mut self[r] where r is a Range<'id>.

impl<'id, T, P, Array, M> IndexMut<RangeFrom<Index<'id, P>>> for Container<'id, Array, M> where
    Array: ContiguousMut<Item = T>, 
[src]

&mut self[i..] where i is an Index<'id, P> which may be an edge index.

impl<'id, T, P, Array, M> IndexMut<RangeTo<Index<'id, P>>> for Container<'id, Array, M> where
    Array: ContiguousMut<Item = T>, 
[src]

&mut self[..i] where i is an Index<'id, P>, which may be an edge index.

impl<'id, T, Array> IndexMut<RangeFull> for Container<'id, Array> where
    Array: ContiguousMut<Item = T>, 
[src]

&mut self[..]

impl<'id, Array, Mode> Debug for Container<'id, Array, Mode> where
    Array: Debug
[src]

Auto Trait Implementations

impl<'id, Array, Mode> Unpin for Container<'id, Array, Mode> where
    Array: Unpin,
    Mode: Unpin

impl<'id, Array, Mode> Sync for Container<'id, Array, Mode> where
    Array: Sync,
    Mode: Sync

impl<'id, Array, Mode> Send for Container<'id, Array, Mode> where
    Array: Send,
    Mode: Send

impl<'id, Array, Mode> UnwindSafe for Container<'id, Array, Mode> where
    Array: UnwindSafe,
    Mode: UnwindSafe

impl<'id, Array, Mode> RefUnwindSafe for Container<'id, Array, Mode> where
    Array: RefUnwindSafe,
    Mode: RefUnwindSafe

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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

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.

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

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

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