Struct RevSlice

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

Source

pub fn len(&self) -> usize

Return the length of the slice.

Source

pub fn get(&self, i: usize) -> Option<&T>

Get element at index i.

See also indexing notation: &foo[i].

Source

pub fn get_mut(&mut self, i: usize) -> Option<&mut T>

Get element at index i.

See also indexing notation: &mut foo[i].

Source

pub fn inner_ref(&self) -> &[T]

Source

pub fn inner_mut(&mut self) -> &mut [T]

Source

pub fn into_boxed_slice(self: Box<Self>) -> Box<[T]>

Source

pub fn iter(&self) -> Rev<Iter<'_, T>>

Return a by-reference iterator

Source

pub fn iter_mut(&mut self) -> Rev<IterMut<'_, T>>

Return a by-mutable-reference iterator

Source

pub fn split_at(&self, i: usize) -> (&Self, &Self)

Source

pub fn split_at_mut(&mut self, i: usize) -> (&mut Self, &mut Self)

Trait Implementations§

Source§

impl<T: Debug> Debug for RevSlice<T>

Source§

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

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

impl<'a, T> Default for &'a RevSlice<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T> Default for &'a mut RevSlice<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T, Slice> From<&'a Slice> for &'a RevSlice<T>
where Slice: AsRef<[T]> + ?Sized,

Source§

fn from(slc: &'a Slice) -> Self

Converts to this type from the input type.
Source§

impl<'a, T, Slice> From<&'a mut Slice> for &'a mut RevSlice<T>
where Slice: AsMut<[T]> + ?Sized,

Source§

fn from(slc: &'a mut Slice) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Box<[T]>> for Box<RevSlice<T>>

Source§

fn from(slc: Box<[T]>) -> Self

Converts to this type from the input type.
Source§

impl<T> Hash for RevSlice<T>
where T: Hash,

Source§

fn hash<H: Hasher>(&self, h: &mut H)

Feeds this value into the given Hasher. Read more
Source§

impl<T, R> Index<R> for RevSlice<T>
where R: IndexRange,

Source§

type Output = RevSlice<T>

The returned type after indexing.
Source§

fn index(&self, index: R) -> &RevSlice<T>

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

impl<T> Index<usize> for RevSlice<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &T

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

impl<T, R> IndexMut<R> for RevSlice<T>
where R: IndexRange,

Source§

fn index_mut(&mut self, index: R) -> &mut RevSlice<T>

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

impl<T> IndexMut<usize> for RevSlice<T>

Source§

fn index_mut(&mut self, i: usize) -> &mut T

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

impl<'a, T> IntoIterator for &'a RevSlice<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Rev<Iter<'a, T>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut RevSlice<T>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = Rev<IterMut<'a, T>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, U> PartialEq<[U]> for RevSlice<T>
where T: PartialEq<U>,

RevSlice compares by logical element sequence.

Source§

fn eq(&self, rhs: &[U]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, U> PartialEq<RevSlice<U>> for RevSlice<T>
where T: PartialEq<U>,

Source§

fn eq(&self, rhs: &RevSlice<U>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> SliceFind for RevSlice<T>

Source§

type Item = T

Source§

fn find<U: ?Sized>(&self, elt: &U) -> Option<usize>
where Self::Item: PartialEq<U>,

Linear search for the first occurrence elt in the slice. Read more
Source§

fn rfind<U: ?Sized>(&self, elt: &U) -> Option<usize>
where Self::Item: PartialEq<U>,

Linear search for the last occurrence elt in the slice. Read more
Source§

impl<T: Eq> Eq for RevSlice<T>

Auto Trait Implementations§

§

impl<T> Freeze for RevSlice<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for RevSlice<T>
where T: RefUnwindSafe,

§

impl<T> Send for RevSlice<T>
where T: Send,

§

impl<T> !Sized for RevSlice<T>

§

impl<T> Sync for RevSlice<T>
where T: Sync,

§

impl<T> Unpin for RevSlice<T>
where T: Unpin,

§

impl<T> UnwindSafe for RevSlice<T>
where T: UnwindSafe,

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