cxx::vector

Type Alias Vector

Source
pub type Vector<T> = CxxVector<T>;
Expand description

Synonym for CxxVector.

To avoid confusion with Rust’s standard library vector you probably shouldn’t import this type with use. Instead, write cxx::Vector<T>, or import and use CxxVector.

Aliased Type§

struct Vector<T> { /* private fields */ }

Implementations

Source§

impl<T> CxxVector<T>
where T: VectorElement,

Source

pub fn new() -> UniquePtr<Self>

Constructs a new heap allocated vector, wrapped by UniquePtr.

The C++ vector is default constructed.

Source

pub fn len(&self) -> usize

Returns the number of elements in the vector.

Matches the behavior of C++ std::vector<T>::size.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

Matches the behavior of C++ std::vector<T>::empty.

Source

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

Returns a reference to an element at the given position, or None if out of bounds.

Source

pub fn index_mut(self: Pin<&mut Self>, pos: usize) -> Option<Pin<&mut T>>

Returns a pinned mutable reference to an element at the given position, or None if out of bounds.

Source

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

Returns a reference to an element without doing bounds checking.

This is generally not recommended, use with caution! Calling this method with an out-of-bounds index is undefined behavior even if the resulting reference is not used.

Matches the behavior of C++ std::vector<T>::operator[] const.

Source

pub unsafe fn index_unchecked_mut( self: Pin<&mut Self>, pos: usize, ) -> Pin<&mut T>

Returns a pinned mutable reference to an element without doing bounds checking.

This is generally not recommended, use with caution! Calling this method with an out-of-bounds index is undefined behavior even if the resulting reference is not used.

Matches the behavior of C++ std::vector<T>::operator[].

Source

pub fn as_slice(&self) -> &[T]
where T: ExternType<Kind = Trivial>,

Returns a slice to the underlying contiguous array of elements.

Source

pub fn as_mut_slice(self: Pin<&mut Self>) -> &mut [T]
where T: ExternType<Kind = Trivial>,

Returns a slice to the underlying contiguous array of elements by mutable reference.

Source

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

Returns an iterator over elements of type &T.

Source

pub fn iter_mut(self: Pin<&mut Self>) -> IterMut<'_, T>

Returns an iterator over elements of type Pin<&mut T>.

Source

pub fn push(self: Pin<&mut Self>, value: T)
where T: ExternType<Kind = Trivial>,

Appends an element to the back of the vector.

Matches the behavior of C++ std::vector<T>::push_back.

Source

pub fn pop(self: Pin<&mut Self>) -> Option<T>
where T: ExternType<Kind = Trivial>,

Removes the last element from a vector and returns it, or None if the vector is empty.

Trait Implementations

Source§

impl<T> Debug for CxxVector<T>
where T: VectorElement + Debug,

Source§

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

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

impl<T> UniquePtrTarget for CxxVector<T>
where T: VectorElement,