VecLike

Trait VecLike 

Source
pub trait VecLike: IntoIterator<Item = Self::T> + Extend<Self::T> {
    type T;

    // Required methods
    fn with_capacity(n: usize) -> Self
       where Self: Sized;
    fn push(&mut self, x: Self::T);
    fn pop(&mut self) -> Option<Self::T>;
    fn len(&self) -> usize;
    fn as_slice(&self) -> &[Self::T];

    // Provided methods
    fn new() -> Self
       where Self: Sized { ... }
    fn map_elements<T2, E2>(self, f: impl FnMut(Self::T) -> T2) -> E2
       where E2: VecLike<T = T2>,
             Self: Sized { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

A trait for mutable growable vectors.

Required Associated Types§

Source

type T

The type of input elements.

Required Methods§

Source

fn with_capacity(n: usize) -> Self
where Self: Sized,

Create an instance of this container with at least n elements allocated.

Source

fn push(&mut self, x: Self::T)

Push an element to the end.

Source

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

Pop an element from the end.

Source

fn len(&self) -> usize

The number of elements.

Source

fn as_slice(&self) -> &[Self::T]

A contiguous slice of memory referring to the elements.

Provided Methods§

Source

fn new() -> Self
where Self: Sized,

Create an instance of this container without allocating any memory.

Also see ConstDefault for an orthogonal trait for const instances.

Source

fn map_elements<T2, E2>(self, f: impl FnMut(Self::T) -> T2) -> E2
where E2: VecLike<T = T2>, Self: Sized,

Convert an instance of this vector into another type.

Source

fn is_empty(&self) -> bool

Whether there are any elements.

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 for Vec<T>

Source§

type T = T

Source§

fn new() -> Self

Source§

fn with_capacity(n: usize) -> Self

Source§

fn push(&mut self, x: T)

Source§

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

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn as_slice(&self) -> &[Self::T]

Implementors§