[go: up one dir, main page]

VecLike

Trait VecLike 

Source
pub trait VecLike<T>:
    Index<usize, Output = T>
    + IndexMut<usize>
    + Index<Range<usize>, Output = [T]>
    + IndexMut<Range<usize>>
    + Index<RangeFrom<usize>, Output = [T]>
    + IndexMut<RangeFrom<usize>>
    + Index<RangeTo<usize>, Output = [T]>
    + IndexMut<RangeTo<usize>>
    + Index<RangeFull, Output = [T]>
    + IndexMut<RangeFull>
    + DerefMut<Target = [T]>
    + Extend<T> {
    // Required methods
    fn push(&mut self, value: T);
    fn pop(&mut self) -> Option<T>;
}
Expand description

Common operations implemented by both Vec and StackVec.

This can be used to write generic code that works with both Vec and StackVec.

§Example

use stackvector::{VecLike, StackVec};

fn initialize<V: VecLike<u8>>(v: &mut V) {
    for i in 0..5 {
        v.push(i);
    }
}

let mut vec = Vec::new();
initialize(&mut vec);

let mut stack_vec = StackVec::<[u8; 8]>::new();
initialize(&mut stack_vec);

Required Methods§

Source

fn push(&mut self, value: T)

Append an element to the vector.

Source

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

Pop an element from the end of the vector.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> VecLike<T> for Vec<T>

Source§

fn push(&mut self, value: T)

Source§

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

Implementors§

Source§

impl<A: Array> VecLike<<A as Array>::Item> for StackVec<A>