Struct Range

Source
pub struct Range<'id, Proof = Unknown> { /* private fields */ }
Expand description

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.

Implementations§

Source§

impl<'id, P> Range<'id, P>

Source

pub fn len(&self) -> usize

Return the length of the range.

Source

pub fn is_empty(&self) -> bool

Return true if the range is empty.

Source

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

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

Source

pub fn start(&self) -> usize

Return the start index.

Source

pub fn end(&self) -> usize

Return the end index.

Source

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

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

Source

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

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

index is a relative index.

Source

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

abs_index is an absolute index

Source

pub fn subdivide(&self, n: usize) -> Subdivide<'id>

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

Source

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

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

Source

pub fn join_cover<Q>(&self, other: Range<'id, Q>) -> Range<'id, P>

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:

// 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
});
Source

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

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

Source

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

Source

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

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

Source

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

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

Return true if the index was incremented.

Source

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

Increment r, clamping to the end of self.

Source

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

Source§

impl<'id, P> Range<'id, P>

Source

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

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

Source

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

Return the middle index, rounding up.

Produces mid where mid = start + len / 2.

Source

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

Return the index past the end of the range.

Source§

impl<'id> Range<'id, NonEmpty>

Source

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

Return the middle index, rounding down.

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn advance(&mut self) -> bool

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.

Source

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

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.

Source

pub fn advance_back(&mut self) -> bool

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§

Source§

impl<'id, P> Clone for Range<'id, P>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'id, P> Debug for Range<'id, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'id, P> Hash for Range<'id, P>

Source§

fn hash<H: Hasher>(&self, h: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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

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

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, r: Range<'id, P>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

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

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

Source§

fn index_mut(&mut self, r: Range<'id, P>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'id> IntoCheckedRange<'id> for Range<'id>

Source§

impl<'id> IntoCheckedRange<'id> for Range<'id, NonEmpty>

Source§

impl<'id, P> IntoIterator for Range<'id, P>

Source§

type Item = Index<'id>

The type of the elements being iterated over.
Source§

type IntoIter = RangeIter<'id>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> RangeIter<'id>

Creates an iterator from a value. Read more
Source§

impl<'id, P> Ord for Range<'id, P>

Compare the order of two ranges.

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

Source§

fn cmp(&self, rhs: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'id, P, Q> PartialEq<Range<'id, Q>> for Range<'id, P>

Source§

fn eq(&self, other: &Range<'id, Q>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'id, P, Q> PartialOrd<Range<'id, Q>> for Range<'id, P>

Compare the order of two ranges.

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

Source§

fn partial_cmp(&self, rhs: &Range<'id, Q>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

fn lt(&self, rhs: &Range<'id, Q>) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'id, P> Provable for Range<'id, P>

Source§

type Proof = P

Source§

type WithoutProof = Range<'id>

Source§

fn no_proof(self) -> Self::WithoutProof

Return a copy of self with the proof parameter set to Unknown.
Source§

impl<'id, P> Copy for Range<'id, P>

Source§

impl<'id, P> Eq for Range<'id, P>

Auto Trait Implementations§

§

impl<'id, Proof> Freeze for Range<'id, Proof>

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.