Skip to main content

VecLike

Trait VecLike 

Source
pub trait VecLike:
    Sized
    + From<Vec<Self::Type>>
    + Clone {
    type Type: Copy + Default + Display + PartialEq;

Show 22 methods // Required methods fn with_capacity(c: usize) -> Self; fn get(&self, i: usize) -> Self::Type; fn set(&mut self, i: usize, val: Self::Type); fn len(&self) -> usize; fn push(&mut self, val: Self::Type); fn pop(&mut self) -> Option<Self::Type>; fn iter_values(&self) -> impl Iterator<Item = Self::Type>; fn clear(&mut self); fn resize(&mut self, new_len: usize, value: Self::Type); fn reserve(&mut self, additional: usize); // Provided methods fn new() -> Self { ... } fn get_checked(&self, i: usize) -> Result<Self::Type, CompVecError> { ... } fn set_checked( &mut self, i: usize, val: Self::Type, ) -> Result<(), CompVecError> { ... } fn is_empty(&self) -> bool { ... } fn append(&mut self, other: &mut Self) { ... } fn insert(&mut self, index: usize, element: Self::Type) { ... } fn remove(&mut self, index: usize) -> Self::Type { ... } fn truncate(&mut self, len: usize) { ... } fn extend_from_slice(&mut self, other: &[Self::Type]) { ... } fn dedup(&mut self) { ... } fn swap_remove(&mut self, index: usize) -> Self::Type { ... } fn split_off(&mut self, at: usize) -> Self { ... }
}
Expand description

Defines functionality for an object, which behaves almost like a Vec.

Required Associated Types§

Required Methods§

Source

fn with_capacity(c: usize) -> Self

Creates a vector like object with capacity.

Source

fn get(&self, i: usize) -> Self::Type

Returns entry at position i as value.

Source

fn set(&mut self, i: usize, val: Self::Type)

Sets entry at position i with value val.

Source

fn len(&self) -> usize

Returns the number of stored objects.

Source

fn push(&mut self, val: Self::Type)

Appends an entry.

Source

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

Returns the last entry and deletes it.

Source

fn iter_values(&self) -> impl Iterator<Item = Self::Type>

Returns an iterator over all values.

Source

fn clear(&mut self)

Removes all values, but capacity may be unaffected.

Source

fn resize(&mut self, new_len: usize, value: Self::Type)

Resizes the vector to a given length.

Source

fn reserve(&mut self, additional: usize)

Reserves additional space for pushing values.

Provided Methods§

Source

fn new() -> Self

Creates an empty vector like object.

Source

fn get_checked(&self, i: usize) -> Result<Self::Type, CompVecError>

Returns entry at position i as value with bounds check beforehand.

Source

fn set_checked(&mut self, i: usize, val: Self::Type) -> Result<(), CompVecError>

Sets entry at position i with value val with bounds check beforehand.

Source

fn is_empty(&self) -> bool

Checks, if the container is empty.

Source

fn append(&mut self, other: &mut Self)

Moves all elements from another Vec-like structure.

Source

fn insert(&mut self, index: usize, element: Self::Type)

Inserts an element at index. This operation may be inefficient, since the vector needs to be restructured.

Source

fn remove(&mut self, index: usize) -> Self::Type

Removes an element at index. This operation may be inefficient, since the vector needs to be restructured.

Source

fn truncate(&mut self, len: usize)

Truncates the vector to len.

Source

fn extend_from_slice(&mut self, other: &[Self::Type])

Appends all elements from the slice.

Source

fn dedup(&mut self)

Removes consecutive duplicates.

Source

fn swap_remove(&mut self, index: usize) -> Self::Type

Swaps the last element with index and resizes vec. Returns the removed element at index.

Source

fn split_off(&mut self, at: usize) -> Self

Splits the collection into two at the given index.

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: Copy + Default + Display + PartialEq> VecLike for Vec<T>

Implement VecLike for Vec in the std-lib.

Source§

type Type = T

Source§

fn with_capacity(c: usize) -> Self

Source§

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

Source§

fn set(&mut self, i: usize, val: T)

Source§

fn len(&self) -> usize

Source§

fn push(&mut self, val: T)

Source§

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

Source§

fn iter_values(&self) -> impl Iterator<Item = T>

Source§

fn append(&mut self, other: &mut Self)

Source§

fn clear(&mut self)

Source§

fn insert(&mut self, index: usize, element: Self::Type)

Source§

fn remove(&mut self, index: usize) -> Self::Type

Source§

fn resize(&mut self, new_len: usize, value: Self::Type)

Source§

fn reserve(&mut self, additional: usize)

Source§

fn extend_from_slice(&mut self, other: &[Self::Type])

Source§

fn dedup(&mut self)

Source§

fn swap_remove(&mut self, index: usize) -> Self::Type

Implementors§

Source§

impl VecLike for BoolVec

Source§

impl<T, U: Integer> VecLike for BitVec<T, U>
where T: FromTruncated<U> + IntoTruncated<U> + Integer,

Source§

type Type = T

Source§

impl<T, U: Integer> VecLike for ByteVec<T, U>
where T: FromTruncated<U> + IntoTruncated<U> + Integer,

Source§

type Type = T

Source§

impl<V: VecLike> VecLike for BlockVec<V>

Source§

type Type = <V as VecLike>::Type