Struct Container

Source
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>

Source

pub fn project(&self) -> &Container<'id, Array>

Source§

impl<'id, Array: TrustedContainer + ?Sized> Container<'id, Array>

Source

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.

Source

pub fn unit_len(&self) -> usize

The length of the container in base item units.

Source

pub fn start<I: Idx>(&self) -> Index<'id, I, Unknown>

The zero index without a proof of contents.

Source

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

The index one past the end of this container.

Source

pub fn empty_range<I: Idx>(&self) -> Range<'id, I, Unknown>

The empty range 0..0.

Source

pub fn range<I: Idx>(&self) -> Range<'id, I, Unknown>

The full range of the container.

Source

pub fn vet<I: Idx>(&self, idx: I) -> Result<Index<'id, I, NonEmpty>, IndexError>

Vet an absolute index.

Source

pub fn vet_range<I: Idx>( &self, r: Range<I>, ) -> Result<Range<'id, I, Unknown>, IndexError>

Vet an absolute range.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn after<I: Idx>( &self, idx: Index<'id, I, NonEmpty>, ) -> Range<'id, I, Unknown>

Return the range after but not including the index.

Source

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.

Source

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.

Source

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.

Source§

impl<'id, Array: TrustedContainer + ?Sized> Container<'id, Box<Array>>

Source

pub fn project(&self) -> &Container<'id, Array>

Available on crate feature std only.
Source§

impl<'id, T> Container<'id, Vec<T>>

Source

pub fn project(&self) -> &Container<'id, [T]>

Available on crate feature std only.
Source§

impl<'id> Container<'id, String>

Source

pub fn project(&self) -> &Container<'id, str>

Available on crate feature std only.

Trait Implementations§

Source§

impl<'id, Array: TrustedContainer + Clone> Clone for Container<'id, Array>

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, Array: TrustedContainer + Debug + ?Sized> Debug for Container<'id, Array>

Source§

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

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

impl<'id, Array: TrustedContainer + ?Sized, I: Idx> Index<Index<'id, I>> for Container<'id, Array>

Source§

type Output = <Array as TrustedContainer>::Item

The returned type after indexing.
Source§

fn index(&self, index: Index<'id, I, NonEmpty>) -> &Self::Output

Performs the indexing (container[index]) operation. 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, Array: TrustedContainer + ?Sized, I: Idx, P> Index<RangeFrom<Index<'id, I, P>>> for Container<'id, Array>

Source§

type Output = <Array as TrustedContainer>::Slice

The returned type after indexing.
Source§

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

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

impl<'id, Array: TrustedContainer + ?Sized> Index<RangeFull> for Container<'id, Array>

Source§

type Output = <Array as TrustedContainer>::Slice

The returned type after indexing.
Source§

fn index(&self, _: RangeFull) -> &Self::Output

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

impl<'id, Array: TrustedContainer + ?Sized, I: Idx, P> Index<RangeTo<Index<'id, I, P>>> for Container<'id, Array>

Source§

type Output = <Array as TrustedContainer>::Slice

The returned type after indexing.
Source§

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

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

impl<'id, Array: TrustedContainer + Copy> Copy for Container<'id, Array>

Auto Trait Implementations§

§

impl<'id, Array> Freeze for Container<'id, Array>
where Array: Freeze + ?Sized,

§

impl<'id, Array> RefUnwindSafe for Container<'id, Array>
where Array: RefUnwindSafe + ?Sized,

§

impl<'id, Array> Send for Container<'id, Array>
where Array: Send + ?Sized,

§

impl<'id, Array> Sync for Container<'id, Array>
where Array: Sync + ?Sized,

§

impl<'id, Array> Unpin for Container<'id, Array>
where Array: Unpin + ?Sized,

§

impl<'id, Array> !UnwindSafe for Container<'id, Array>

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.