#[repr(C, packed(1))]pub struct CxxVector<T> { /* private fields */ }
Expand description
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§
Source§impl<T> CxxVector<T>where
T: VectorElement,
impl<T> CxxVector<T>where
T: VectorElement,
Sourcepub fn new() -> UniquePtr<CxxVector<T>> ⓘ
pub fn new() -> UniquePtr<CxxVector<T>> ⓘ
Constructs a new heap allocated vector, wrapped by UniquePtr.
The C++ vector is default constructed.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the vector.
Matches the behavior of C++ std::vector<T>::size.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the vector contains no elements.
Matches the behavior of C++ std::vector<T>::empty.
Sourcepub fn get(&self, pos: usize) -> Option<&T>
pub fn get(&self, pos: usize) -> Option<&T>
Returns a reference to an element at the given position, or None
if
out of bounds.
Sourcepub fn index_mut(
self: Pin<&mut CxxVector<T>>,
pos: usize,
) -> Option<Pin<&mut T>>
pub fn index_mut( self: Pin<&mut CxxVector<T>>, pos: usize, ) -> Option<Pin<&mut T>>
Returns a pinned mutable reference to an element at the given position,
or None
if out of bounds.
Sourcepub unsafe fn get_unchecked(&self, pos: usize) -> &T
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.
Sourcepub unsafe fn index_unchecked_mut(
self: Pin<&mut CxxVector<T>>,
pos: usize,
) -> Pin<&mut T>
pub unsafe fn index_unchecked_mut( self: Pin<&mut CxxVector<T>>, 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[].
Sourcepub fn as_slice(&self) -> &[T]where
T: ExternType<Kind = Trivial>,
pub fn as_slice(&self) -> &[T]where
T: ExternType<Kind = Trivial>,
Returns a slice to the underlying contiguous array of elements.
Sourcepub fn as_mut_slice(self: Pin<&mut CxxVector<T>>) -> &mut [T]where
T: ExternType<Kind = Trivial>,
pub fn as_mut_slice(self: Pin<&mut CxxVector<T>>) -> &mut [T]where
T: ExternType<Kind = Trivial>,
Returns a slice to the underlying contiguous array of elements by mutable reference.
Sourcepub fn iter_mut(self: Pin<&mut CxxVector<T>>) -> IterMut<'_, T> ⓘ
pub fn iter_mut(self: Pin<&mut CxxVector<T>>) -> IterMut<'_, T> ⓘ
Returns an iterator over elements of type Pin<&mut T>
.
Sourcepub fn push(self: Pin<&mut CxxVector<T>>, value: T)where
T: ExternType<Kind = Trivial>,
pub fn push(self: Pin<&mut CxxVector<T>>, 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.
Trait Implementations§
Source§impl<'a, T> IntoIterator for &'a CxxVector<T>where
T: VectorElement,
impl<'a, T> IntoIterator for &'a CxxVector<T>where
T: VectorElement,
Source§impl<'a, T> IntoIterator for Pin<&'a mut CxxVector<T>>where
T: VectorElement,
impl<'a, T> IntoIterator for Pin<&'a mut CxxVector<T>>where
T: VectorElement,
impl<T> UniquePtrTarget for CxxVector<T>where
T: VectorElement,
Auto Trait Implementations§
impl<T> Freeze for CxxVector<T>
impl<T> RefUnwindSafe for CxxVector<T>where
T: RefUnwindSafe,
impl<T> Send for CxxVector<T>where
T: Send,
impl<T> Sync for CxxVector<T>where
T: Sync,
impl<T> !Unpin for CxxVector<T>
impl<T> UnwindSafe for CxxVector<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more