pub struct Prefix<Tag> { /* private fields */ }
Expand description
The length of a particular slice (or a number of slices).
The encapsulated length field is guaranteed to be at most the length of each of the slices with the exact same tag. In other words, all indices strictly smaller than this number are safe.
This allows this instance to construct indices that are validated to be able to soundly access the slices without required any particular slice instance. In particular, the construct might happen by a numerical algorithm independent of the slices and across method bounds where the compiler’s optimizer and inline pass is no longer aware of the connection and would otherwise insert another check when the slice is indexed later.
Implementations§
source§impl<T: Tag> Prefix<T>
impl<T: Tag> Prefix<T>
sourcepub fn with_tag<NewT>(self, less: TagLessEq<T, NewT>) -> Prefix<NewT>
pub fn with_tag<NewT>(self, less: TagLessEq<T, NewT>) -> Prefix<NewT>
Interpret this with the tag of a set of potentially longer slices.
The proof of inequality was performed in any of the possible constructors that allow the
instance of TagLessEq
to exist in the first place.
sourcepub fn index(self, idx: usize) -> Option<Idx<usize, T>>
pub fn index(self, idx: usize) -> Option<Idx<usize, T>>
Construct an index to a single element.
This method return Some
when the index is smaller than the length.
sourcepub fn range(self, from: usize, to: usize) -> Option<Idx<Range<usize>, T>>
pub fn range(self, from: usize, to: usize) -> Option<Idx<Range<usize>, T>>
Construct an index to a range of element.
This method return Some
when the indices are ordered and to
does not exceed the length.
sourcepub fn range_from(self, from: usize) -> Option<Idx<RangeFrom<usize>, T>>
pub fn range_from(self, from: usize) -> Option<Idx<RangeFrom<usize>, T>>
Construct an index to a range from an element.
This method return Some
when from
does not exceed the length.
sourcepub fn range_from_self(self) -> Idx<RangeFrom<usize>, T>
pub fn range_from_self(self) -> Idx<RangeFrom<usize>, T>
Construct an index to a range starting at this length.
This method might return an index for an empty range.
sourcepub fn range_to(self, to: usize) -> Option<Idx<RangeTo<usize>, T>>
pub fn range_to(self, to: usize) -> Option<Idx<RangeTo<usize>, T>>
Construct an index to a range up to an element.
This method return Some
when to
does not exceed the length.
sourcepub fn range_to_self(self) -> Idx<RangeTo<usize>, T>
pub fn range_to_self(self) -> Idx<RangeTo<usize>, T>
Construct an index to a range up, exclusive, to this length.
This method might return an index for an empty range.
sourcepub fn range_between(self, other: Self) -> Idx<Range<usize>, T>
pub fn range_between(self, other: Self) -> Idx<Range<usize>, T>
Construct an index referring to the unordered range from one element to another.
This method might return an empty range. The order of arguments does not matter.
sourcepub fn range_full(self) -> Idx<RangeFull, T>
pub fn range_full(self) -> Idx<RangeFull, T>
Construct an index to all elements.
This method exists mostly for completeness sake. There is no bounds check when accessing a
complete slice with ..
.
sourcepub fn saturating_sub(self, sub: usize) -> Self
pub fn saturating_sub(self, sub: usize) -> Self
Create a smaller length.