Struct odds::slice::RevSlice
[−]
[src]
#[repr(C)]pub struct RevSlice<T>(_);
A reversed view of a slice.
The RevSlice
is a random accessible range of elements;
it wraps a regular slice but presents the underlying elements in
reverse order.
Example
use odds::slice::RevSlice; let mut data = [0; 8]; { let mut rev = <&mut RevSlice<_>>::from(&mut data); for (i, elt) in rev.iter_mut().enumerate() { *elt = i; } assert_eq!(&rev[..4], &[0, 1, 2, 3][..]); } assert_eq!(&data, &[7, 6, 5, 4, 3, 2, 1, 0]);
Not visible in rustdoc:
- A boxed slice can be reversed too:
impl<T> From<Box<[T]>> for Box<RevSlice<T>>
.
Methods
impl<T> RevSlice<T>
[src]
fn len(&self) -> usize
Return the length of the slice.
fn get(&self, i: usize) -> Option<&T>
Get element at index i
.
See also indexing notation: &foo[i]
.
fn get_mut(&mut self, i: usize) -> Option<&mut T>
Get element at index i
.
See also indexing notation: &mut foo[i]
.
fn inner_ref(&self) -> &[T]
fn inner_mut(&mut self) -> &mut [T]
fn into_boxed_slice(self: Box<Self>) -> Box<[T]>
fn iter(&self) -> Rev<Iter<T>>
Return a by-reference iterator
fn iter_mut(&mut self) -> Rev<IterMut<T>>
Return a by-mutable-reference iterator
fn split_at(&self, i: usize) -> (&Self, &Self)
fn split_at_mut(&mut self, i: usize) -> (&mut Self, &mut Self)
Trait Implementations
impl<T> SliceFind for RevSlice<T>
[src]
type Item = T
fn find<U: ?Sized>(&self, elt: &U) -> Option<usize> where
Self::Item: PartialEq<U>,
Self::Item: PartialEq<U>,
Linear search for the first occurrence elt
in the slice. Read more
fn rfind<U: ?Sized>(&self, elt: &U) -> Option<usize> where
Self::Item: PartialEq<U>,
Self::Item: PartialEq<U>,
Linear search for the last occurrence elt
in the slice. Read more
impl<T: Debug> Debug for RevSlice<T>
[src]
impl<T: Eq> Eq for RevSlice<T>
[src]
impl<T, U> PartialEq<RevSlice<U>> for RevSlice<T> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
fn eq(&self, rhs: &RevSlice<U>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<T, U> PartialEq<[U]> for RevSlice<T> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
RevSlice
compares by logical element sequence.
fn eq(&self, rhs: &[U]) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<T> Hash for RevSlice<T> where
T: Hash,
[src]
T: Hash,
fn hash<H: Hasher>(&self, h: &mut H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the state provided.
impl<'a, T, Slice: ?Sized> From<&'a Slice> for &'a RevSlice<T> where
Slice: AsRef<[T]>,
[src]
Slice: AsRef<[T]>,
fn from(slc: &'a Slice) -> Self
Performs the conversion.
impl<'a, T, Slice: ?Sized> From<&'a mut Slice> for &'a mut RevSlice<T> where
Slice: AsMut<[T]>,
[src]
Slice: AsMut<[T]>,
fn from(slc: &'a mut Slice) -> Self
Performs the conversion.
impl<T> Index<usize> for RevSlice<T>
[src]
type Output = T
The returned type after indexing
fn index(&self, i: usize) -> &T
The method for the indexing (container[index]
) operation
impl<T> IndexMut<usize> for RevSlice<T>
[src]
fn index_mut(&mut self, i: usize) -> &mut T
The method for the mutable indexing (container[index]
) operation
impl<'a, T> Default for &'a RevSlice<T>
[src]
impl<'a, T> Default for &'a mut RevSlice<T>
[src]
impl<T, R> Index<R> for RevSlice<T> where
R: IndexRange,
[src]
R: IndexRange,
type Output = RevSlice<T>
The returned type after indexing
fn index(&self, index: R) -> &RevSlice<T>
The method for the indexing (container[index]
) operation
impl<T, R> IndexMut<R> for RevSlice<T> where
R: IndexRange,
[src]
R: IndexRange,
fn index_mut(&mut self, index: R) -> &mut RevSlice<T>
The method for the mutable indexing (container[index]
) operation
impl<'a, T> IntoIterator for &'a RevSlice<T>
[src]
type Item = &'a T
The type of the elements being iterated over.
type IntoIter = Rev<Iter<'a, T>>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more