[−][src]Struct indexing::Range
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]
&self,
other: Range<'id, Q>
) -> Result<Range<'id, <(P, Q) as ProofAdd>::Sum>, IndexingError> where
(P, Q): ProofAdd,
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]
(P, Q): ProofAdd,
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 });
pub fn join_cover_both<Q>(
&self,
other: Range<'id, Q>
) -> Range<'id, <(P, Q) as ProofAdd>::Sum> where
(P, Q): ProofAdd,
[src]
&self,
other: Range<'id, Q>
) -> Range<'id, <(P, Q) as ProofAdd>::Sum> where
(P, Q): ProofAdd,
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]
impl<'id, P> Eq for Range<'id, P>
[src]
impl<'id, P> Clone for Range<'id, P>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[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.
fn partial_cmp(&self, rhs: &Range<'id, Q>) -> Option<Ordering>
[src]
fn lt(&self, rhs: &Range<'id, Q>) -> bool
[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'id, P, Q> PartialEq<Range<'id, Q>> for Range<'id, P>
[src]
fn eq(&self, other: &Range<'id, Q>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
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.
fn cmp(&self, rhs: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[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?
ⓘImportant traits for RangeIter<'id>fn into_iter(self) -> RangeIter<'id>
[src]
impl<'id, P> Copy for Range<'id, P>
[src]
impl<'id, P> Hash for Range<'id, P>
[src]
fn hash<H: Hasher>(&self, h: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'id, T, Array, P, M> Index<Range<'id, P>> for Container<'id, Array, M> where
Array: Contiguous<Item = T>,
[src]
Array: Contiguous<Item = T>,
&self[r]
where r
is a Range<'id>
.
type Output = [T]
The returned type after indexing.
fn index(&self, r: Range<'id, P>) -> &Self::Output
[src]
impl<'id, Array, P, M> IndexMut<Range<'id, P>> for Container<'id, Array, M> where
Array: ContiguousMut,
[src]
Array: ContiguousMut,
&mut self[r]
where r
is a Range<'id>
.
impl<'id, P> Debug for Range<'id, P>
[src]
Auto Trait Implementations
impl<'id, Proof> Send for Range<'id, Proof> where
Proof: Send,
Proof: Send,
impl<'id, Proof> Unpin for Range<'id, Proof> where
Proof: Unpin,
Proof: Unpin,
impl<'id, Proof> Sync for Range<'id, Proof> where
Proof: Sync,
Proof: Sync,
impl<'id, Proof> UnwindSafe for Range<'id, Proof> where
Proof: UnwindSafe,
Proof: UnwindSafe,
impl<'id, Proof> RefUnwindSafe for Range<'id, Proof> where
Proof: RefUnwindSafe,
Proof: RefUnwindSafe,
Blanket Implementations
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<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
impl<T> From<T> for 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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,