Struct CxxVector
#[repr(C, packed(1))]
pub struct CxxVector<T> { /* private fields */ }
Binding to C++ std::vector<T, std::allocator<T>>.
Invariants
As an invariant of this API and the static analysis of the cxx::bridge
macro, in Rust code we can never obtain a CxxVector by value. Instead in
Rust code we will only ever look at a vector behind a reference or smart
pointer, as in &CxxVector<T> or UniquePtr<CxxVector<T>>.
Implementations
impl<T> CxxVector<T>
where
T: VectorElement,
fn new() -> UniquePtr<Self>Constructs a new heap allocated vector, wrapped by UniquePtr.
The C++ vector is default constructed.
fn len(&self) -> usizeReturns the number of elements in the vector.
Matches the behavior of C++ std::vector<T>::size.
fn capacity(&self) -> usizeReturns the capacity of the vector.
Matches the behavior of C++ std::vector<T>::capacity.
fn is_empty(&self) -> boolReturns true if the vector contains no elements.
Matches the behavior of C++ std::vector<T>::empty.
fn get(&self, pos: usize) -> Option<&T>Returns a reference to an element at the given position, or
Noneif out of bounds.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
Noneif out of bounds.This method cannot be named "get_mut" due to a conflict with
Pin::get_mut.unsafe fn get_unchecked(&self, pos: usize) -> &TReturns 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.
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[].
This method cannot be named "get_unchecked_mut" due to a conflict with
Pin::get_unchecked_mut.fn as_slice(&self) -> &[T] where T: ExternType<Kind = Trivial>,Returns a slice to the underlying contiguous array of elements.
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.
fn iter(&self) -> Iter<'_, T>Returns an iterator over elements of type
&T.fn iter_mut(self: Pin<&mut Self>) -> IterMut<'_, T>Returns an iterator over elements of type
Pin<&mut T>.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.
fn pop(self: Pin<&mut Self>) -> Option<T> where T: ExternType<Kind = Trivial>,Removes the last element from a vector and returns it, or
Noneif the vector is empty.fn reserve(self: Pin<&mut Self>, additional: usize)Ensures that this vector's capacity is at least
additionalelements larger than its length.The capacity may be increased by more than
additionalelements if the implementation chooses, to amortize the cost of frequent reallocations.The meaning of the argument is not the same as std::vector<T>::reserve in C++. The C++ standard library and Rust standard library both have a
reservemethod on vectors, but in C++ code the argument always refers to total capacity, whereas in Rust code it always refers to additional capacity. This API onCxxVectorfollows the Rust convention, the same way that for the length accessor we use the Rust conventionallen()naming and not C++size().Panics
Panics if the new capacity overflows usize, or if
Tis not move-constructible in C++.
Trait Implementations
impl<T> Debug for CxxVector<T>
where
T: VectorElement + Debug,
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
impl<T> UniquePtrTarget for CxxVector<T>
where
T: VectorElement,
Auto Trait Implementations
impl<T> !Unpin for CxxVector<T>
impl<T> Freeze for CxxVector<T>
where
PhantomData<[T]>: Freeze,
impl<T> RefUnwindSafe for CxxVector<T>
where
PhantomData<[T]>: RefUnwindSafe,
impl<T> Send for CxxVector<T>
where
PhantomData<[T]>: Send,
impl<T> Sync for CxxVector<T>
where
PhantomData<[T]>: Sync,
impl<T> UnsafeUnpin for CxxVector<T>
where
PhantomData<[T]>: UnsafeUnpin,
impl<T> UnwindSafe for CxxVector<T>
where
PhantomData<[T]>: UnwindSafe,
Blanket Implementations
impl<T> Any for CxxVector<T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for CxxVector<T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for CxxVector<T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for CxxVector<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for CxxVector<T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for CxxVector<T>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for CxxVector<T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>