pub struct RevSlice<T>(/* private fields */);
Expand description
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>>
.
Implementations§
Source§impl<T> RevSlice<T>
impl<T> RevSlice<T>
Sourcepub fn get(&self, i: usize) -> Option<&T>
pub fn get(&self, i: usize) -> Option<&T>
Get element at index i
.
See also indexing notation: &foo[i]
.
Sourcepub fn get_mut(&mut self, i: usize) -> Option<&mut T>
pub fn get_mut(&mut self, i: usize) -> Option<&mut T>
Get element at index i
.
See also indexing notation: &mut foo[i]
.
pub fn inner_ref(&self) -> &[T]
pub fn inner_mut(&mut self) -> &mut [T]
pub fn into_boxed_slice(self: Box<Self>) -> Box<[T]>
pub fn split_at(&self, i: usize) -> (&Self, &Self)
pub fn split_at_mut(&mut self, i: usize) -> (&mut Self, &mut Self)
Trait Implementations§
Source§impl<'a, T, Slice> From<&'a mut Slice> for &'a mut RevSlice<T>
impl<'a, T, Slice> From<&'a mut Slice> for &'a mut RevSlice<T>
Source§fn from(slc: &'a mut Slice) -> Self
fn from(slc: &'a mut Slice) -> Self
Converts to this type from the input type.
Source§impl<T, R> Index<R> for RevSlice<T>where
R: IndexRange,
impl<T, R> Index<R> for RevSlice<T>where
R: IndexRange,
Source§impl<T, R> IndexMut<R> for RevSlice<T>where
R: IndexRange,
impl<T, R> IndexMut<R> for RevSlice<T>where
R: IndexRange,
Source§impl<'a, T> IntoIterator for &'a RevSlice<T>
impl<'a, T> IntoIterator for &'a RevSlice<T>
Source§impl<'a, T> IntoIterator for &'a mut RevSlice<T>
impl<'a, T> IntoIterator for &'a mut RevSlice<T>
Source§impl<T, U> PartialEq<[U]> for RevSlice<T>where
T: PartialEq<U>,
RevSlice
compares by logical element sequence.
impl<T, U> PartialEq<[U]> for RevSlice<T>where
T: PartialEq<U>,
RevSlice
compares by logical element sequence.