rstd 0.1.0
Loading...
Searching...
No Matches
alloc::vec::Vec< T > Class Template Referenceexport
module rstd.alloc

A contiguous growable array type, analogous to Rust's Vec<T>. More...

Public Member Functions

constexpr Vec ()
 Creates an empty Vec with no allocation.
 
constexpr auto as_slice () const noexcept -> slice< T >
 Returns a slice containing the entire vector.
 
constexpr auto as_mut_slice () noexcept -> mut_ptr< T[]>
 Returns a mutable slice containing the entire vector.
 
constexpr auto as_ptr () const noexcept -> ptr< T >
 Returns a const pointer to the first element of the vector.
 
auto into_boxed_slice () noexcept -> Box< T[]>
 Converts this Vec into a Box<T[]>, transferring ownership of all elements.
 
constexpr void push (T &&value)
 Appends an element to the back of the vector by moving it.
 
constexpr auto pop () -> Option< T >
 Removes the last element from the vector and returns it, or None if empty.
 
constexpr void push_back (const T &value)
 Appends a cloned copy of the element to the back of the vector.
 
constexpr void pop_back ()
 Removes the last element from the vector, discarding it.
 
constexpr T & at (usize index)
 Returns a mutable reference to the element at the given index, panicking if out of bounds.
 
constexpr const T & at (usize index) const
 Returns a const reference to the element at the given index, panicking if out of bounds.
 
constexpr T & operator[] (usize index)
 Indexes into the vector, panicking if out of bounds.
 
constexpr const T & operator[] (usize index) const
 Indexes into the vector (const), panicking if out of bounds.
 
constexpr usize len () const
 Returns the number of elements in the vector.
 
constexpr usize capacity () const
 Returns the number of elements the vector can hold without reallocating.
 
constexpr bool is_empty () const
 Returns true if the vector contains no elements.
 
constexpr void clear ()
 Clears the vector, destroying all elements but not deallocating memory.
 
constexpr T remove (usize index)
 Removes and returns the element at the given index, shifting subsequent elements left.
 
constexpr auto begin () noexcept
 Returns a mutable iterator to the beginning.
 
constexpr auto end () noexcept
 Returns a mutable iterator to the end.
 
constexpr auto begin () const noexcept
 Returns a const iterator to the beginning.
 
constexpr auto end () const noexcept
 Returns a const iterator to the end.
 

Static Public Member Functions

static constexpr auto make () -> Self
 Creates a new empty Vec.
 
static auto with_capacity (usize capacity) -> Self
 Creates a new empty Vec with at least the specified capacity.
 

Detailed Description

template<typename T>
class alloc::vec::Vec< T >

A contiguous growable array type, analogous to Rust's Vec<T>.

Template Parameters
TThe element type, which must be Sized.

Member Function Documentation

◆ as_mut_slice()

template<typename T >
auto alloc::vec::Vec< T >::as_mut_slice ( ) -> mut_ptr<T[]>
inlineconstexprnoexcept

Returns a mutable slice containing the entire vector.

Returns
A mutable pointer to a slice over all elements.

◆ as_ptr()

template<typename T >
auto alloc::vec::Vec< T >::as_ptr ( ) const -> ptr<T>
inlineconstexprnoexcept

Returns a const pointer to the first element of the vector.

Returns
A const pointer to the underlying buffer.

◆ as_slice()

template<typename T >
auto alloc::vec::Vec< T >::as_slice ( ) const -> slice<T>
inlineconstexprnoexcept

Returns a slice containing the entire vector.

Returns
An immutable slice<T> over all elements.

◆ at() [1/2]

template<typename T >
T & alloc::vec::Vec< T >::at ( usize index)
inlineconstexpr

Returns a mutable reference to the element at the given index, panicking if out of bounds.

Parameters
indexThe index of the element.
Returns
A mutable reference to the element.

◆ at() [2/2]

template<typename T >
const T & alloc::vec::Vec< T >::at ( usize index) const
inlineconstexpr

Returns a const reference to the element at the given index, panicking if out of bounds.

Parameters
indexThe index of the element.
Returns
A const reference to the element.

◆ capacity()

template<typename T >
usize alloc::vec::Vec< T >::capacity ( ) const
inlineconstexpr

Returns the number of elements the vector can hold without reallocating.

Returns
The current capacity.

◆ into_boxed_slice()

template<typename T >
auto alloc::vec::Vec< T >::into_boxed_slice ( ) -> Box<T[]>
inlinenoexcept

Converts this Vec into a Box<T[]>, transferring ownership of all elements.

Returns
A boxed slice containing the vector's elements.

◆ len()

template<typename T >
usize alloc::vec::Vec< T >::len ( ) const
inlineconstexpr

Returns the number of elements in the vector.

Returns
The length of the vector.

◆ make()

template<typename T >
static constexpr auto alloc::vec::Vec< T >::make ( ) -> Self
inlinestaticconstexpr

Creates a new empty Vec.

Returns
An empty Vec.

◆ pop()

template<typename T >
auto alloc::vec::Vec< T >::pop ( ) -> Option<T>
inlineconstexpr

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

Returns
An Option<T> containing the removed element.

◆ push()

template<typename T >
void alloc::vec::Vec< T >::push ( T && value)
inlineconstexpr

Appends an element to the back of the vector by moving it.

Parameters
valueThe value to append.

◆ push_back()

template<typename T >
void alloc::vec::Vec< T >::push_back ( const T & value)
inlineconstexpr

Appends a cloned copy of the element to the back of the vector.

Parameters
valueThe value to clone and append.

◆ remove()

template<typename T >
T alloc::vec::Vec< T >::remove ( usize index)
inlineconstexpr

Removes and returns the element at the given index, shifting subsequent elements left.

Parameters
indexThe index of the element to remove.
Returns
The removed element.

◆ with_capacity()

template<typename T >
static auto alloc::vec::Vec< T >::with_capacity ( usize capacity) -> Self
inlinestatic

Creates a new empty Vec with at least the specified capacity.

Parameters
capacityThe minimum number of elements the Vec can hold without reallocating.
Returns
A Vec with preallocated capacity.

The documentation for this class was generated from the following file: