pub struct Container<'id, Array: TrustedContainer + ?Sized> { /* private fields */ }
Expand description
A branded container, that allows access only to indices and ranges with
the exact same brand in the 'id
parameter.
The elements in the underlying data structure are accessible partly through special purpose methods, and through indexing/slicing.
The container can be indexed with self[i]
where i
is a trusted,
dereferenceable index or range. Indexing like this uses no runtime
checking at all, as it is statically guaranteed correct.
Implementations§
Source§impl<'id, Array: TrustedContainer + ?Sized> Container<'id, Array>
impl<'id, Array: TrustedContainer + ?Sized> Container<'id, Array>
Sourcepub fn untrusted(&self) -> &Array
pub fn untrusted(&self) -> &Array
This container without the branding.
§Note
The returned lifetime of &Array
is not 'id
! It’s completely
valid to drop the container during the scope
, in which case this
reference would become invalid. If you need a longer lifetime,
consider using scope_ref
such that the reference is guaranteed to
live for the entire scope.
Sourcepub fn start<I: Idx>(&self) -> Index<'id, I, Unknown>
pub fn start<I: Idx>(&self) -> Index<'id, I, Unknown>
The zero index without a proof of contents.
Sourcepub fn end<I: Idx>(&self) -> Index<'id, I, Unknown>
pub fn end<I: Idx>(&self) -> Index<'id, I, Unknown>
The index one past the end of this container.
Sourcepub fn empty_range<I: Idx>(&self) -> Range<'id, I, Unknown>
pub fn empty_range<I: Idx>(&self) -> Range<'id, I, Unknown>
The empty range 0..0
.
Sourcepub fn vet<I: Idx>(&self, idx: I) -> Result<Index<'id, I, NonEmpty>, IndexError>
pub fn vet<I: Idx>(&self, idx: I) -> Result<Index<'id, I, NonEmpty>, IndexError>
Vet an absolute index.
Sourcepub fn vet_range<I: Idx>(
&self,
r: Range<I>,
) -> Result<Range<'id, I, Unknown>, IndexError>
pub fn vet_range<I: Idx>( &self, r: Range<I>, ) -> Result<Range<'id, I, Unknown>, IndexError>
Vet an absolute range.
Sourcepub fn split_at<I: Idx, P>(
&self,
idx: Index<'id, I, P>,
) -> (Range<'id, I, Unknown>, Range<'id, I, P>)
pub fn split_at<I: Idx, P>( &self, idx: Index<'id, I, P>, ) -> (Range<'id, I, Unknown>, Range<'id, I, P>)
Split the container in two at the given index, such that the second range contains the index.
Sourcepub fn split_after<I: Idx>(
&self,
idx: Index<'id, I, NonEmpty>,
) -> (Range<'id, I, NonEmpty>, Range<'id, I, Unknown>)
pub fn split_after<I: Idx>( &self, idx: Index<'id, I, NonEmpty>, ) -> (Range<'id, I, NonEmpty>, Range<'id, I, Unknown>)
Split the container in two after the given index, such that the first range contains the index.
Sourcepub fn split_around<I: Idx, P>(
&self,
r: Range<'id, I, P>,
) -> (Range<'id, I, Unknown>, Range<'id, I, Unknown>)
pub fn split_around<I: Idx, P>( &self, r: Range<'id, I, P>, ) -> (Range<'id, I, Unknown>, Range<'id, I, Unknown>)
Split around the range r
creating ranges 0..r.start
and r.end..
.
The input r
and return values (s, t)
cover teh whole container in
the order s
, r
, t
.
Sourcepub fn before<I: Idx, P>(&self, idx: Index<'id, I, P>) -> Range<'id, I, Unknown>
pub fn before<I: Idx, P>(&self, idx: Index<'id, I, P>) -> Range<'id, I, Unknown>
Return the range before but not including the index.
Sourcepub fn after<I: Idx>(
&self,
idx: Index<'id, I, NonEmpty>,
) -> Range<'id, I, Unknown>
pub fn after<I: Idx>( &self, idx: Index<'id, I, NonEmpty>, ) -> Range<'id, I, Unknown>
Return the range after but not including the index.
Sourcepub fn advance<I: Idx>(
&self,
idx: Index<'id, I, NonEmpty>,
) -> Option<Index<'id, I, NonEmpty>>
pub fn advance<I: Idx>( &self, idx: Index<'id, I, NonEmpty>, ) -> Option<Index<'id, I, NonEmpty>>
Advance an index to the next item in the container, if there is one.
Sourcepub fn advance_by<I: Idx, P>(
&self,
idx: Index<'id, I, P>,
offset: usize,
) -> Result<Index<'id, I, NonEmpty>, IndexError>
pub fn advance_by<I: Idx, P>( &self, idx: Index<'id, I, P>, offset: usize, ) -> Result<Index<'id, I, NonEmpty>, IndexError>
Advance an index by a given base unit offset, if the index at said offset is a valid item index.
Sourcepub fn decrease_by<I: Idx, P>(
&self,
idx: Index<'id, I, P>,
offset: usize,
) -> Result<Index<'id, I, NonEmpty>, IndexError>
pub fn decrease_by<I: Idx, P>( &self, idx: Index<'id, I, P>, offset: usize, ) -> Result<Index<'id, I, NonEmpty>, IndexError>
Decrease an index by a given base unit offset, if the index at said offset is a valid item index.