[−][src]Struct indexing::container::Container
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 like self[i]
where i
is a trusted
dereferenceable index
or range, and equivalently using &self[i..]
or &self[..i]
where
i
is a trusted index. Indexing like this uses no runtime bounds checking
at all, and it statically guaranteed to be in bounds.
The container can also be sliced for its complete range: &self[..]
.
Methods
impl<'id, Array, T, Mode> Container<'id, Array, Mode> where
Array: Trustworthy<Item = T>,
[src]
Array: Trustworthy<Item = T>,
pub fn len(&self) -> usize
[src]
pub fn only_index(self) -> Container<'id, Array, OnlyIndex>
[src]
Convert the container into an only-indexing container.
The container no longer allows pointer access. This unlocks some features.
pub fn empty_range(&self) -> Range<'id>
[src]
Return the range [0, 0)
pub fn range(&self) -> Range<'id>
[src]
Return the full range of the Container.
pub fn vet(&self, index: usize) -> Result<Index<'id>, IndexingError>
[src]
Vet the absolute index
.
pub fn vet_range(&self, r: Range<usize>) -> Result<Range<'id>, IndexingError>
[src]
Vet the range r
.
pub fn split_at<P>(&self, index: Index<'id, P>) -> (Range<'id>, Range<'id, P>)
[src]
pub fn split_after(
&self,
index: Index<'id>
) -> (Range<'id, NonEmpty>, Range<'id>)
[src]
&self,
index: Index<'id>
) -> (Range<'id, NonEmpty>, Range<'id>)
Split in two ranges, where the first includes the index
and the second
starts with the following index.
pub fn split_around<P>(&self, r: Range<'id, P>) -> (Range<'id>, Range<'id>)
[src]
Split around the Range r
: Return ranges corresponding to 0..r.start
and r.end..
.
So that input r
and return values (s, t)
cover the whole container
in the order s
, r
, t
.
pub fn before<P>(&self, index: Index<'id, P>) -> Range<'id>
[src]
Return the range before (not including) the index itself
pub fn after(&self, index: Index<'id>) -> Range<'id>
[src]
Return the range after (not including) the index itself
pub fn range_of<P, R>(&self, r: R) -> Range<'id> where
R: OnePointRange<Index<'id, P>>,
[src]
R: OnePointRange<Index<'id, P>>,
pub fn forward(&self, index: &mut Index<'id>) -> bool
[src]
Increment index
, if doing so would still be in bounds.
Return true
if the index was incremented.
pub fn forward_by(&self, index: &mut Index<'id>, offset: usize) -> bool
[src]
Increment index
, if doing so would still be in bounds.
Return true
if the index was incremented.
pub fn forward_range_by<P>(&self, r: Range<'id, P>, offset: usize) -> Range<'id>
[src]
Increment r
, clamping to the end of the Container.
pub fn backward(&self, index: &mut Index<'id>) -> bool
[src]
Decrement index
, if doing so would still be in bounds.
Return true
if the index was decremented.
pub fn scan_from<'b, F>(
&'b self,
index: Index<'id>,
f: F
) -> Range<'id, NonEmpty> where
F: FnMut(&'b T) -> bool,
T: 'b,
Array: Contiguous<Item = T>,
[src]
&'b self,
index: Index<'id>,
f: F
) -> Range<'id, NonEmpty> where
F: FnMut(&'b T) -> bool,
T: 'b,
Array: Contiguous<Item = T>,
Examine the elements after index
in order from lower indices towards higher.
While the closure returns true
, continue scan and include the scanned
element in the range.
Result always includes index
in the range
pub fn scan_from_rev<'b, F>(
&'b self,
index: Index<'id>,
f: F
) -> Range<'id, NonEmpty> where
F: FnMut(&'b T) -> bool,
T: 'b,
Array: Contiguous<Item = T>,
[src]
&'b self,
index: Index<'id>,
f: F
) -> Range<'id, NonEmpty> where
F: FnMut(&'b T) -> bool,
T: 'b,
Array: Contiguous<Item = T>,
Examine the elements before index
in order from higher indices towards lower.
While the closure returns true
, continue scan and include the scanned
element in the range.
Result always includes index
in the range.
pub fn scan_range<'b, F, P>(
&'b self,
range: Range<'id, P>,
f: F
) -> (Range<'id>, Range<'id>) where
F: FnMut(&'b T) -> bool,
T: 'b,
Array: Contiguous<Item = T>,
[src]
&'b self,
range: Range<'id, P>,
f: F
) -> (Range<'id>, Range<'id>) where
F: FnMut(&'b T) -> bool,
T: 'b,
Array: Contiguous<Item = T>,
Examine the elements range
in order from lower indices towards higher.
While the closure returns true
, continue scan and include the scanned
element in the range.
pub fn swap(&mut self, i: Index<'id>, j: Index<'id>) where
Array: GetUncheckedMut,
[src]
Array: GetUncheckedMut,
Swap elements at i
and j
(they may be equal).
pub fn rotate1_up<R>(&mut self, r: R) where
Array: Contiguous + GetUncheckedMut,
R: IntoCheckedRange<'id>,
[src]
Array: Contiguous + GetUncheckedMut,
R: IntoCheckedRange<'id>,
Rotate elements in the range r
by one step to the right (towards higher indices)
pub fn rotate1_down<R>(&mut self, r: R) where
Array: Contiguous + GetUncheckedMut,
R: IntoCheckedRange<'id>,
[src]
Array: Contiguous + GetUncheckedMut,
R: IntoCheckedRange<'id>,
Rotate elements in the range r
by one step to the left (towards lower indices)
pub fn index_twice<P, Q>(
&mut self,
r: Range<'id, P>,
s: Range<'id, Q>
) -> Result<(&mut [T], &mut [T]), IndexingError> where
Array: ContiguousMut,
[src]
&mut self,
r: Range<'id, P>,
s: Range<'id, Q>
) -> Result<(&mut [T], &mut [T]), IndexingError> where
Array: ContiguousMut,
Index by two nonoverlapping ranges, where r
is before s
.
pub fn zip_mut_raw<P, Q, F>(&mut self, r: Range<'id, P>, s: Range<'id, Q>, f: F) where
F: FnMut(*mut T, *mut T),
Array: GetUncheckedMut,
[src]
F: FnMut(*mut T, *mut T),
Array: GetUncheckedMut,
Zip by raw pointer (will be indentical if ranges have same starting point)
impl<'id, Array, T> Container<'id, Array, OnlyIndex> where
Array: Pushable<Item = T>,
[src]
Array: Pushable<Item = T>,
Methods specific to only index mode
pub fn push(&mut self, element: T) -> Index<'id>
[src]
Add one element to the underlying storage, and return its index.
All outstanding indices remain valid, only the length of the container is now larger.
pub fn insert<Q>(&mut self, index: Index<'id, Q>, element: T)
[src]
Insert one element in the underlying storage at index
.
All outstanding indices remain valid (in bounds), but elements have shifted.
impl<'id, Array, T, Mode> Container<'id, Array, Mode> where
Array: Trustworthy<Item = T> + FixedLength,
[src]
Array: Trustworthy<Item = T> + FixedLength,
pub fn make_twin<Array2>(
&self,
arr: Array2
) -> Result<Container<'id, Array2, OnlyIndex>, IndexingError> where
Array2: Trustworthy + FixedLength,
[src]
&self,
arr: Array2
) -> Result<Container<'id, Array2, OnlyIndex>, IndexingError> where
Array2: Trustworthy + FixedLength,
Create a twin Container, that admits the same branded indices as self
Checks the compatibilty (length) of both arrays and returns the twin container if it is admissible.
The twin container is OnlyIndex-marked, because only indices/index ranges transfer between twins, and branded raw pointers of course not.
Trait Implementations
impl<'id, Array, Mode> Clone for Container<'id, Array, Mode> where
Array: Clone + FixedLength,
[src]
Array: Clone + FixedLength,
A container can be cloned if the inner array can (typically a shared slice).
But containers of vectors can not be cloned:
use indexing::scope; scope(vec![0; 10], |v| { let _u = v.clone(); });
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'id, Array, M> Index<Index<'id, NonEmpty>> for Container<'id, Array, M> where
Array: GetUnchecked,
[src]
Array: GetUnchecked,
&self[i]
where i
is an Index<'id>
.
type Output = Array::Item
The returned type after indexing.
fn index(&self, index: Index<'id>) -> &Self::Output
[src]
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, T, P, Array, M> Index<RangeFrom<Index<'id, P>>> for Container<'id, Array, M> where
Array: Contiguous<Item = T>,
[src]
Array: Contiguous<Item = T>,
&self[i..]
where i
is an Index<'id, P>
which may be an edge index.
type Output = [T]
The returned type after indexing.
fn index(&self, r: RangeFrom<Index<'id, P>>) -> &[T]
[src]
impl<'id, T, P, Array, M> Index<RangeTo<Index<'id, P>>> for Container<'id, Array, M> where
Array: Contiguous<Item = T>,
[src]
Array: Contiguous<Item = T>,
&self[..i]
where i
is an Index<'id, P>
, which may be an edge index.
type Output = [T]
The returned type after indexing.
fn index(&self, r: RangeTo<Index<'id, P>>) -> &[T]
[src]
impl<'id, T, Array, M> Index<RangeFull> for Container<'id, Array, M> where
Array: Contiguous<Item = T>,
[src]
Array: Contiguous<Item = T>,
&self[..]
impl<'id, Array, M> IndexMut<Index<'id, NonEmpty>> for Container<'id, Array, M> where
Array: GetUncheckedMut,
[src]
Array: GetUncheckedMut,
&mut self[i]
where i
is an Index<'id>
.
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, T, P, Array, M> IndexMut<RangeFrom<Index<'id, P>>> for Container<'id, Array, M> where
Array: ContiguousMut<Item = T>,
[src]
Array: ContiguousMut<Item = T>,
&mut self[i..]
where i
is an Index<'id, P>
which may be an edge index.
impl<'id, T, P, Array, M> IndexMut<RangeTo<Index<'id, P>>> for Container<'id, Array, M> where
Array: ContiguousMut<Item = T>,
[src]
Array: ContiguousMut<Item = T>,
&mut self[..i]
where i
is an Index<'id, P>
, which may be an edge index.
impl<'id, T, Array> IndexMut<RangeFull> for Container<'id, Array> where
Array: ContiguousMut<Item = T>,
[src]
Array: ContiguousMut<Item = T>,
&mut self[..]
impl<'id, Array, Mode> Debug for Container<'id, Array, Mode> where
Array: Debug,
[src]
Array: Debug,
Auto Trait Implementations
impl<'id, Array, Mode> Unpin for Container<'id, Array, Mode> where
Array: Unpin,
Mode: Unpin,
Array: Unpin,
Mode: Unpin,
impl<'id, Array, Mode> Sync for Container<'id, Array, Mode> where
Array: Sync,
Mode: Sync,
Array: Sync,
Mode: Sync,
impl<'id, Array, Mode> Send for Container<'id, Array, Mode> where
Array: Send,
Mode: Send,
Array: Send,
Mode: Send,
impl<'id, Array, Mode> UnwindSafe for Container<'id, Array, Mode> where
Array: UnwindSafe,
Mode: UnwindSafe,
Array: UnwindSafe,
Mode: UnwindSafe,
impl<'id, Array, Mode> RefUnwindSafe for Container<'id, Array, Mode> where
Array: RefUnwindSafe,
Mode: RefUnwindSafe,
Array: RefUnwindSafe,
Mode: RefUnwindSafe,
Blanket Implementations
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<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,