Struct boxcar::Vec

source ·
pub struct Vec<T> { /* private fields */ }
Expand description

A concurrent, append-only vector.

See the crate documentation for details.

§Notes

The bucket array is stored inline, meaning that the Vec<T> is quite large. It is expected that you store it behind an Arc or similar.

Implementations§

source§

impl<T> Vec<T>

source

pub const fn new() -> Vec<T>

Constructs a new, empty Vec<T>.

§Examples
let vec: boxcar::Vec<i32> = boxcar::Vec::new();
source

pub fn with_capacity(capacity: usize) -> Vec<T>

Constructs a new, empty Vec<T> with the specified capacity.

The vector will be able to hold at least capacity elements without reallocating.

§Examples
let vec = boxcar::Vec::with_capacity(10);

for i in 0..10 {
    // will not allocate
    vec.push(i);
}

// may allocate
vec.push(11);
source

pub fn reserve(&self, additional: usize)

Reserves capacity for at least additional more elements to be inserted in the given Vec<T>. The collection may reserve more space to avoid frequent reallocations.

Does nothing if capacity is already sufficient.

§Examples
let vec = boxcar::Vec::new();
vec.reserve(10);

for i in 0..10 {
    // will not allocate
    vec.push(i);
}

// may allocate
vec.push(11);
source

pub fn push(&self, value: T) -> usize

Appends an element to the back of the vector, returning the index it was inserted into.

§Examples
let vec = boxcar::vec![1, 2];
assert_eq!(vec.push(3), 2);
assert_eq!(vec, [1, 2, 3]);
source

pub fn count(&self) -> usize

Returns the number of elements in the vector.

Note that due to concurrent writes, it is not guaranteed that all elements 0..vec.count() are initialized.

§Examples
let vec = boxcar::Vec::new();
assert_eq!(vec.count(), 0);
vec.push(1);
vec.push(2);
assert_eq!(vec.count(), 2);
source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

§Examples
let vec = boxcar::Vec::new();
assert!(vec.is_empty());

vec.push(1);
assert!(!vec.is_empty());
source

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

Returns a reference to the element at the given index.

§Examples
let vec = boxcar::vec![10, 40, 30];
assert_eq!(Some(&40), vec.get(1));
assert_eq!(None, vec.get(3));
source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Returns a mutable reference to the element at the given index.

§Examples
let mut vec = boxcar::vec![10, 40, 30];
assert_eq!(Some(&mut 40), vec.get_mut(1));
assert_eq!(None, vec.get_mut(3));
source

pub unsafe fn get_unchecked(&self, index: usize) -> &T

Returns a reference to an element, without doing bounds checking or verifying that the element is fully initialized.

For a safe alternative see get.

§Safety

Calling this method with an out-of-bounds index, or for an element that is being concurrently initialized is undefined behavior, even if the resulting reference is not used.

§Examples
let vec = boxcar::vec![1, 2, 4];

unsafe {
    assert_eq!(vec.get_unchecked(1), &2);
}
source

pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T

Returns a mutable reference to an element, without doing bounds checking or verifying that the element is fully initialized.

For a safe alternative see get.

§Safety

Calling this method with an out-of-bounds index is undefined behavior, even if the resulting reference is not used.

§Examples
let mut vec = boxcar::vec![1, 2, 4];

unsafe {
    assert_eq!(vec.get_unchecked_mut(1), &mut 2);
}
source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the vector.

Values are yielded in the form (index, value). The vector may have in-progress concurrent writes that create gaps, so index may not be strictly sequential.

§Examples
let vec = boxcar::vec![1, 2, 4];
let mut iterator = vec.iter();

assert_eq!(iterator.next(), Some((0, &1)));
assert_eq!(iterator.next(), Some((1, &2)));
assert_eq!(iterator.next(), Some((2, &4)));
assert_eq!(iterator.next(), None);

Trait Implementations§

source§

impl<T: Clone> Clone for Vec<T>

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Vec<T>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T> Default for Vec<T>

source§

fn default() -> Vec<T>

Returns the “default value” for a type. Read more
source§

impl<T> Extend<T> for Vec<T>

source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T> FromIterator<T> for Vec<T>

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T> Index<usize> for Vec<T>

§

type Output = T

The returned type after indexing.
source§

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

Performs the indexing (container[index]) operation. Read more
source§

impl<'a, T> IntoIterator for &'a Vec<T>

§

type Item = (usize, &'a T)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> IntoIterator for Vec<T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<A, T> PartialEq<A> for Vec<T>
where A: AsRef<[T]>, T: PartialEq,

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq> Eq for Vec<T>

Auto Trait Implementations§

§

impl<T> !Freeze for Vec<T>

§

impl<T> RefUnwindSafe for Vec<T>

§

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

§

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

§

impl<T> Unpin for Vec<T>

§

impl<T> !UnwindSafe for Vec<T>

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> 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,

§

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>,

§

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>,

§

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.