Struct Vector

Source
pub struct Vector<T>
where T: PartialEq + Clone + Debug,
{ /* private fields */ }
Expand description

A resizable collection of elements that can be randomly accessed and altered.

Implementations§

Source§

impl<T> Vector<T>
where T: PartialEq + Clone + Debug,

Source

pub fn new() -> Self

Creates a new empty ‘vector’.

Source

pub fn from_vec(v: &Vec<T>) -> Self

Creates a new ‘vector’ that contains the elements in the specified vector.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new ‘vector’ with the specified capacity.

Source

pub fn with_length(length: usize, item: &T) -> Self

Creates a new ‘vector’ with the specified length with all values set to the specified value.

Trait Implementations§

Source§

impl<T> ArrayCollection<T> for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

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

Returns the element at the specified index or None if the index is out-of-bounds.

Source§

fn index_list(&self, item: &T) -> Option<Vec<usize>>

Returns a vector of indices that contain the specified element or None if the ‘vector’ doesn’t contain the specified element.

Source§

fn index_of(&self, item: &T) -> Option<usize>

Returns the first index of the specified element or None if the ‘vector’ doesn’t contain the specified element.

Source§

fn last_index_of(&self, item: &T) -> Option<usize>

Returns the last index of the specified element or None if the ‘vector’ doesn’t contain the specified element.

Source§

fn set(&mut self, index: usize, item: &T) -> Option<T>

Sets the element at the specified index to the specified value. Returns the item being replaced at the specified index.

§Panics

This function panics if the specified index is out-of-bounds.

Source§

fn slice(&mut self, r: Range<usize>) -> Box<[T]>

Returns a ‘slice’ of this ‘vector’ within the specified index ‘range’.

§Panics

This function panics if the specified range is out-of-bounds.

Source§

impl<T> Clear for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

fn clear(&mut self)

Clears all elements from this ‘vector’.

Source§

impl<T> Clone for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

fn clone(&self) -> Self

Returns a clone of this ‘vector’.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Collection for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

type Element = T

The element type.

Source§

fn capacity(&self) -> usize

Returns the capacity of this ‘vector’.

Source§

fn contains(&self, item: &T) -> bool

Returns true if this ‘vector’ contains the specified element.

Source§

fn contains_all(&self, vec: &Vec<T>) -> bool

Returns true if this ‘vector’ contains the specified vector.

Source§

fn to_vec(&self) -> Vec<T>

Returns a vector containing the elements of this ‘vector’.

Source§

impl<T> Debug for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

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

Displays the debug information for this ‘vector’.

Source§

impl<T> Empty for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

fn is_empty(&self) -> bool

Returns true if this ‘vector’ is empty.

Source§

impl<T> Index<usize> for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

type Output = T

Output type.

Source§

fn index(&self, index: usize) -> &Self::Output

Returns the value of this ‘vector’ at the specified index.

§Panics

This function panics if the index is out-of-bounds.

Source§

impl<T> IndexMut<usize> for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Returns the value of this ‘vector’ at the specified index.

§Panics

This function panics if the index is out-of-bounds.

Source§

impl<T> IntoIterator for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

type Item = T

The Item type.

Source§

type IntoIter = IntoIter<T>

The IntoIter type.

Source§

fn into_iter(self) -> Self::IntoIter

Converts this ‘vector’ into an ‘iterator’.

Source§

impl<T> Len for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

fn len(&self) -> usize

Returns the length of this ‘vector’.

Source§

impl<T> ListCollection<T> for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

fn append(&mut self, item: T) -> bool

Appends the specified element to the end of the ‘vector’. Returns true if successful.

§Panics

This function panics if the new capacity exceeds isize::MAX bytes.

Source§

fn append_all(&mut self, vec: Vec<T>) -> bool

Appends the specified vector to the end of the ‘vector’. Returns true if successful.

§Panics

This function panics if the new capacity exceeds isize::MAX bytes.

Source§

fn insert(&mut self, index: usize, item: T) -> bool

Inserts the specified element at the specified index. Returns true if successful.

§Panics

This function panics if the specified index is greater than the ‘vector’s’ length.

Source§

fn insert_all(&mut self, index: usize, vec: Vec<T>) -> bool

Inserts the specified vector at the specified index. Returns true if successful.

§Panics

This function panics if the specified index is greater than the ‘vector’s’ length.

Source§

fn prepend(&mut self, item: T) -> bool

Prepends the specified element to the start of the ‘vector’. Returns true if successful.

Source§

fn prepend_all(&mut self, vec: Vec<T>) -> bool

Prepends the specified vector to the start of the ‘vector’. Returns true if successful.

Source§

fn remove(&mut self, item: T) -> bool

Removes the last occurrence of the specified element from this ‘vector’. Returns true if the element was removed or false if it was not found.

Source§

fn remove_any(&mut self, item: T) -> usize

Removes any occurrence of the specified value from this ‘vector’. Returns the number of occurrences that were removed.

Source§

fn remove_all(&mut self, vec: Vec<T>) -> usize

Removes the elements in the specified vector, if they are in this ‘vector’. Returns the number of removed elements. All occurrences of the elements in the specified vector are removed.

Source§

fn remove_last(&mut self, item: T) -> bool

Removes the last occurrence of the specified element from this ‘vector’. Returns true if the element was removed or false if it was not found.

Source§

fn retain_all(&mut self, vec: Vec<T>) -> usize

Removes all elements from this ‘vector’ that are not in the specified vector. Returns the new size of this ‘vector’ after retaining.

Source§

impl<T> PartialEq for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

fn eq(&self, other: &Self) -> bool

Returns true if this ‘vector’ and the specified ‘vector’ are equal, meaning they are the same length and contain the same elements.

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> Reversible for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

fn reverse(&mut self) -> Self

Returns a copy of this ‘vector’ in reverse order.

Source§

impl<T> Sortable for Vector<T>

Source§

fn is_sorted(&self) -> bool

Returns true if this ‘vector’ is sorted in ascending order.

Source§

fn is_sorted_rev(&self) -> bool

Returns true if this ‘vector’ is sorted in descending order.

Source§

fn sort(&mut self)

Sorts the elements in this ‘vector’ in ascending order.

Source§

fn sort_rev(&mut self)

Sorts the elements in this ‘vector’ in descending order.

Source§

impl<T> VectorCollection<T> for Vector<T>
where T: PartialEq + Clone + Debug,

Source§

fn extend(&mut self, additional: usize, item: &T)

Extends the length of this ‘vector’ by the specified additional amount with all new elements set to the specified value.

Source§

fn reserve(&mut self, additional: usize)

Reserves capacity for the specified number of additional elements.

§Panics

This function panics if the new capacity exceeds isize::MAX bytes.

Source§

fn resize(&mut self, length: usize, item: &T)

Resizes the ‘vector’ to the specified length with any new elements set to the specified value.

Source§

fn shrink(&mut self)

Sets the capacity to match the current length of this ‘vector’.

Source§

fn truncate(&mut self, length: usize)

Truncates the length of this ‘vector’ to the specified length.

Auto Trait Implementations§

§

impl<T> Freeze for Vector<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Vector<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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.