Struct Range

Source
pub struct Range<'id, I: Idx = u32, Emptiness = Unknown> { /* private fields */ }
Expand description

A branded range.

Range<'id> only indexes the container instantiated with the exact same lifetime for the parameter 'id created by the scope function.

The range may carry a proof of non-emptiness (Emptiness), which enables further operations.

Implementations§

Source§

impl<'id, I: Idx> Range<'id, I, Unknown>

Source

pub fn from<P, Q>(start: Index<'id, I, P>, end: Index<'id, I, Q>) -> Self

Construct a range from two trusted indices.

Source§

impl<'id, I: Idx, Emptiness> Range<'id, I, Emptiness>

Source

pub fn untrusted(&self) -> Range<I>

This range without the branding.

Source

pub fn erased(&self) -> Range<'id, I, Unknown>

This range without the emptiness proof.

Source

pub fn len(&self) -> I

The length of the range.

Source

pub fn is_empty(&self) -> bool

true if the range is empty.

Source

pub fn nonempty(&self) -> Option<Range<'id, I, NonEmpty>>

Try to create a proof that the range is nonempty.

Source

pub fn start(&self) -> Index<'id, I, Emptiness>

The starting index. (Accessible if the range is NonEmpty.)

Source

pub fn end(&self) -> Index<'id, I, Unknown>

The ending index.

Source

pub fn split_at<E>( &self, index: Index<'id, I, E>, ) -> Option<(Range<'id, I>, Range<'id, I>)>

Split around the middle index if it is in this range.

Source

pub fn contains_in<Array: TrustedContainer>( &self, index: I, container: &Container<'id, Array>, ) -> Option<Index<'id, I, NonEmpty>>

If the index is a valid absolute index within this range.

Source

pub fn contains<P>( &self, index: Index<'id, I, P>, ) -> Option<Index<'id, I, NonEmpty>>

If the index is within this range. Provides a nonempty proof.

Source

pub fn join<Q>( &self, other: Range<'id, I, Q>, ) -> Option<Range<'id, I, <(Emptiness, Q) as ProofAdd>::Sum>>

Join together two adjacent ranges. (They must be exactly touching, non-overlapping, and in order.)

Source

pub fn join_cover<Q>( &self, other: Range<'id, I, Q>, ) -> Range<'id, I, <(Emptiness, Q) as ProofAdd>::Sum>

Extend the range to cover all of other, including any space between.

Source

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

Create two empty ranges, at the front and the back of this range.

Source§

impl<'id, I: Idx> Range<'id, I, NonEmpty>

Source

pub fn advance_in<Array: TrustedContainer>( &mut self, container: &Container<'id, Array>, ) -> bool

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

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

Trait Implementations§

Source§

impl<'id, I: Idx, Emptiness> Clone for Range<'id, I, Emptiness>

Source§

fn clone(&self) -> Self

Returns a duplicate 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, I: Idx, Emptiness> Debug for Range<'id, I, Emptiness>

Source§

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

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

impl<'id, I: Idx, Emptiness> From<Range<Index<'id, I, Emptiness>>> for Range<'id, I, Unknown>

§Note

In order to use this impl, you’ll likely need to erase the emptiness proof from the indices to create the range. This doesn’t lose any Range proof.

Source§

fn from(r: Range<Index<'id, I, Emptiness>>) -> Self

Converts to this type from the input type.
Source§

impl<'id, I: Idx, Emptiness> Hash for Range<'id, I, Emptiness>

Source§

fn hash<H: Hasher>(&self, state: &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, Array: TrustedContainer + ?Sized, I: Idx, P> Index<Range<'id, I, P>> for Container<'id, Array>

Source§

type Output = <Array as TrustedContainer>::Slice

The returned type after indexing.
Source§

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

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

impl<'id, I: Idx, P, Q> PartialEq<Range<'id, I, Q>> for Range<'id, I, P>

Source§

fn eq(&self, other: &Range<'id, I, 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, I: Idx, Emptiness> Copy for Range<'id, I, Emptiness>

Source§

impl<'id, I: Idx, Emptiness> Eq for Range<'id, I, Emptiness>

Auto Trait Implementations§

§

impl<'id, I, Emptiness> Freeze for Range<'id, I, Emptiness>
where I: Freeze,

§

impl<'id, I, Emptiness> RefUnwindSafe for Range<'id, I, Emptiness>
where I: RefUnwindSafe, Emptiness: RefUnwindSafe,

§

impl<'id, I, Emptiness> Send for Range<'id, I, Emptiness>
where I: Send, Emptiness: Send,

§

impl<'id, I, Emptiness> Sync for Range<'id, I, Emptiness>
where I: Sync, Emptiness: Sync,

§

impl<'id, I, Emptiness> Unpin for Range<'id, I, Emptiness>
where I: Unpin, Emptiness: Unpin,

§

impl<'id, I = u32, Emptiness = Unknown> !UnwindSafe for Range<'id, I, Emptiness>

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, Array> TrustedItem<&Array> for T
where T: TrustedItem<Array> + ?Sized, Array: TrustedContainer<Item = T> + ?Sized,

Source§

type Unit = <T as TrustedItem<Array>>::Unit

Source§

fn vet<'id, I>( idx: I, container: &Container<'id, &Array>, ) -> Result<Index<'id, I, Unknown>, IndexError>
where I: Idx,

Vet an index for being on item boundaries. Read more
Source§

fn after<'id, I>( this: Index<'id, I>, container: &Container<'id, &Array>, ) -> Index<'id, I, Unknown>
where I: Idx,

Increment an index to the next item, potentially leaving the container.
Source§

fn advance<'id, I>( this: Index<'id, I>, container: &Container<'id, &Array>, ) -> Option<Index<'id, I>>
where I: Idx,

Advance an index to the next item, if a next item exists.
Source§

impl<T> TrustedItem<[T]> for T

Source§

type Unit = T

Source§

fn vet<'id, I>( idx: I, container: &Container<'id, [T]>, ) -> Result<Index<'id, I, Unknown>, IndexError>
where I: Idx,

Vet an index for being on item boundaries. Read more
Source§

fn after<'id, I>( this: Index<'id, I>, _: &Container<'id, [T]>, ) -> Index<'id, I, Unknown>
where I: Idx,

Increment an index to the next item, potentially leaving the container.
Source§

fn advance<'id, I>( this: Index<'id, I>, container: &Container<'id, [T]>, ) -> Option<Index<'id, I>>
where I: Idx,

Advance an index to the next item, if a next item exists.
Source§

impl<T, Array> TrustedItem<Box<Array>> for T
where T: TrustedItem<Array> + ?Sized, Array: TrustedContainer<Item = T> + ?Sized,

Source§

type Unit = <T as TrustedItem<Array>>::Unit

Source§

fn vet<'id, I>( idx: I, container: &Container<'id, Box<Array>>, ) -> Result<Index<'id, I, Unknown>, IndexError>
where I: Idx,

Vet an index for being on item boundaries. Read more
Source§

fn after<'id, I>( this: Index<'id, I>, container: &Container<'id, Box<Array>>, ) -> Index<'id, I, Unknown>
where I: Idx,

Increment an index to the next item, potentially leaving the container.
Source§

fn advance<'id, I>( this: Index<'id, I>, container: &Container<'id, Box<Array>>, ) -> Option<Index<'id, I>>
where I: Idx,

Advance an index to the next item, if a next item exists.
Source§

impl<T> TrustedItem<Vec<T>> for T
where T: TrustedItem<[T]>,

Source§

type Unit = <T as TrustedItem<[T]>>::Unit

Source§

fn vet<'id, I>( idx: I, container: &Container<'id, Vec<T>>, ) -> Result<Index<'id, I, Unknown>, IndexError>
where I: Idx,

Vet an index for being on item boundaries. Read more
Source§

fn after<'id, I>( this: Index<'id, I>, container: &Container<'id, Vec<T>>, ) -> Index<'id, I, Unknown>
where I: Idx,

Increment an index to the next item, potentially leaving the container.
Source§

fn advance<'id, I>( this: Index<'id, I>, container: &Container<'id, Vec<T>>, ) -> Option<Index<'id, I>>
where I: Idx,

Advance an index to the next item, if a next item exists.
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.