[][src]Struct indexing::Range

pub struct Range<'id, Proof = Unknown> { /* fields omitted */ }

A branded range.

Range<'id> only indexes the container instantiated with the exact same particular lifetime for the parameter 'id at its inception from the scope() function.

The Range may carry a proof of nonemptiness (type parameter Proof), which enables further methods.

The range is delimited by a start index and an end index. Some methods will use offsets relative the the start of a range, others will use “absolute indices” which are offsets relative to the base Container itself.

Methods

impl<'id, P> Range<'id, P>[src]

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

Return the length of the range.

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

Return true if the range is empty.

pub fn nonempty(&self) -> Result<Range<'id, NonEmpty>, IndexingError>[src]

Try to create a proof that the Range is nonempty; return a Result where the Ok branch carries a non-empty Range.

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

Return the start index.

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

Return the end index.

pub fn split_in_half(self) -> (Range<'id>, Range<'id, P>)[src]

Split the range in half, with the upper middle index landing in the latter half. Proof of length P transfers to the latter half.

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

Split to length index; if past the end, return false and clamp to the end

index is a relative index.

pub fn contains(&self, abs_index: usize) -> Option<Index<'id>>[src]

abs_index is an absolute index

Important traits for Subdivide<'id>
pub fn subdivide(&self, n: usize) -> Subdivide<'id>[src]

Return an iterator that divides the range in n parts, in as even length chunks as possible.

pub fn join<Q>(
    &self,
    other: Range<'id, Q>
) -> Result<Range<'id, <(P, Q) as ProofAdd>::Sum>, IndexingError> where
    (P, Q): ProofAdd
[src]

Join together two adjacent ranges (they must be exactly touching, and in left to right order).

pub fn join_cover<Q>(&self, other: Range<'id, Q>) -> Range<'id, P> where
    (P, Q): ProofAdd
[src]

Extend the range to the end of other, including any space in between

The following example exists only to check that it fails to compile:

This example deliberately fails to compile
// Bug from https://github.com/bluss/indexing/issues/12
use indexing::scope;

let array = [0, 1, 2, 3, 4, 5];
scope(&array[..], |arr| {
    let left = arr.vet_range(0..2).unwrap();
    let left = left.nonempty().unwrap();
    let (_, right) = arr.range().frontiers();
    let joined = right.join_cover(left);
    let ix = joined.first();
    arr[ix];  //~ ERROR: Can't index by ix, because it's an edge index
});

pub fn join_cover_both<Q>(
    &self,
    other: Range<'id, Q>
) -> Range<'id, <(P, Q) as ProofAdd>::Sum> where
    (P, Q): ProofAdd
[src]

Extend the range to start and end of other, including any space in between

pub fn as_range(&self) -> Range<usize>[src]

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

Return two empty ranges, at the front and the back of the range respectively

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

Increment index, if doing so would still be before the end of the range

Return true if the index was incremented.

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

Increment r, clamping to the end of self.

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

impl<'id, P> Range<'id, P>[src]

pub fn first(&self) -> Index<'id, P>[src]

Return the first index in the range (The index is accessible if the range is NonEmpty).

pub fn upper_middle(&self) -> Index<'id, P>[src]

Return the middle index, rounding up.

Produces mid where mid = start + len / 2.

pub fn past_the_end(self) -> Index<'id, Unknown>[src]

Return the index past the end of the range.

impl<'id> Range<'id, NonEmpty>[src]

pub fn lower_middle(&self) -> Index<'id>[src]

Return the middle index, rounding down.

Produces mid where mid = start + (len - 1)/ 2.

pub fn last(&self) -> Index<'id>[src]

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

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

pub fn advance_(&self) -> Result<Range<'id, NonEmpty>, IndexingError>[src]

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

Increase the range's start, if the result is still a non-empty range.

Return true if stepped successfully, false if the range would be empty.

pub fn advance_by(&mut self, offset: usize) -> bool[src]

Increase the range's start, if the result is still a non-empty range.

Return true if stepped successfully, false if the range would be empty.

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

Decrease the range's end, if the result is still a non-empty range.

Return true if stepped successfully, false if the range would be empty.

Trait Implementations

impl<'id> IntoCheckedRange<'id> for Range<'id>[src]

impl<'id> IntoCheckedRange<'id> for Range<'id, NonEmpty>[src]

impl<'id, P> Provable for Range<'id, P>[src]

type Proof = P

type WithoutProof = Range<'id, Unknown>

impl<'id, P> Clone for Range<'id, P>[src]

impl<'id, P, Q> PartialOrd<Range<'id, Q>> for Range<'id, P>[src]

Compare the order of two ranges.

Ranges compare like an ordered pair of indices, and the proof parameter does not matter.

impl<'id, P> Copy for Range<'id, P>[src]

impl<'id, P> Eq for Range<'id, P>[src]

impl<'id, P> IntoIterator for Range<'id, P>[src]

type Item = Index<'id>

The type of the elements being iterated over.

type IntoIter = RangeIter<'id>

Which kind of iterator are we turning this into?

impl<'id, P> Ord for Range<'id, P>[src]

Compare the order of two ranges.

Ranges compare like an ordered pair of indices, and the proof parameter does not matter.

impl<'id, P, Q> PartialEq<Range<'id, Q>> for Range<'id, P>[src]

impl<'id, P> Debug for Range<'id, P>[src]

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, 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, P> Hash for Range<'id, P>[src]

Auto Trait Implementations

impl<'id, Proof> Unpin for Range<'id, Proof> where
    Proof: Unpin

impl<'id, Proof> Sync for Range<'id, Proof> where
    Proof: Sync

impl<'id, Proof> Send for Range<'id, Proof> where
    Proof: Send

impl<'id, Proof> UnwindSafe for Range<'id, Proof> where
    Proof: UnwindSafe

impl<'id, Proof> RefUnwindSafe for Range<'id, Proof> where
    Proof: RefUnwindSafe

Blanket Implementations

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

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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

type Owned = T

The resulting type after obtaining ownership.

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]