array_tool::vec

Trait Shift

Source
pub trait Shift<T> {
    // Required methods
    fn shift(&mut self) -> Option<T>;
    fn unshift(&mut self, other: T);
}
Expand description

Removes, or Adds, the first element of self.

Required Methods§

Source

fn shift(&mut self) -> Option<T>

Removes and returns the first item from the vector

§Example
use array_tool::vec::Shift;

let mut x = vec![0,1,2,3];
assert_eq!(x.shift(), Some(0));
assert_eq!(x, vec![1,2,3]);
Source

fn unshift(&mut self, other: T)

Insert item at the beginning of the vector. No return value.

§Example
use array_tool::vec::Shift;

let mut x = vec![1,2,3];
x.unshift(0);
assert_eq!(x, vec![0,1,2,3]);

Implementations on Foreign Types§

Source§

impl<T: PartialEq> Shift<T> for Vec<T>

Source§

fn shift(&mut self) -> Option<T>

Source§

fn unshift(&mut self, other: T)

Implementors§