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

A pointer type that uniquely owns a heap allocation of type T. More...

Public Member Functions

auto clone () -> Self
 Creates a new Box by cloning the contained value.
 
void clone_from (Self &source)
 Replaces the contents of this Box with a clone of the source.
 
constexpr auto into_raw () &&noexcept -> mut_ptr< T >
 Consumes the Box, returning the wrapped raw pointer without deallocating.
 
constexpr auto get () noexcept -> mut_ptr< T >::value_type *
 Returns a raw pointer to the contained value.
 
constexpr auto operator-> () noexcept
 Dereferences the Box, providing mutable access to the inner value.
 
constexpr auto operator-> () const noexcept
 Dereferences the Box, providing const access to the inner value.
 
constexpr operator bool () const noexcept
 Returns true if this Box holds a valid (non-null) pointer.
 
void reset () noexcept
 Destroys the contained value and deallocates the memory.
 
constexpr auto as_ref () const noexcept -> ref< T >
 Returns an immutable reference to the contained value.
 
constexpr auto as_ptr () const noexcept -> ptr< T >
 Returns a const pointer to the contained value.
 
constexpr auto as_mut_ptr () const noexcept -> mut_ptr< T >
 Returns a mutable pointer to the contained value.
 
auto clone () -> Self
 Creates a new Box by cloning all elements of the contained array.
 

Static Public Member Functions

template<typename... Args>
requires Impled<T, Sized>
static auto make (Args &&... args) -> Box
 Allocates memory on the heap and constructs T in place with the given arguments.
 
template<typename U >
static auto make (U &&in) -> Box requires(! Impled< T, Sized > &&mtp::dyn_traits< T >::template Impled< U >)
 Allocates memory on the heap for a dynamically-sized trait object.
 
static auto pin (T &&in) -> Pin< Box >
 Constructs a new Pin<Box<T>> by moving the value onto the heap.
 
static constexpr Box from_raw (mut_ptr< T > raw) noexcept
 Constructs a Box from a raw mutable pointer.
 

Detailed Description

template<typename T>
class alloc::boxed::Box< T >

A pointer type that uniquely owns a heap allocation of type T.

Template Parameters
TThe type of the value stored on the heap.

Member Function Documentation

◆ as_mut_ptr()

template<typename T >
auto alloc::boxed::Box< T >::as_mut_ptr ( ) const -> mut_ptr<T>
inlineconstexprnoexcept

Returns a mutable pointer to the contained value.

Returns
A mut_ptr<T> to the boxed value.

◆ as_ptr()

template<typename T >
auto alloc::boxed::Box< T >::as_ptr ( ) const -> ptr<T>
inlineconstexprnoexcept

Returns a const pointer to the contained value.

Returns
A ptr<T> to the boxed value.

◆ as_ref()

template<typename T >
auto alloc::boxed::Box< T >::as_ref ( ) const -> ref<T>
inlineconstexprnoexcept

Returns an immutable reference to the contained value.

Returns
A ref<T> to the boxed value.

◆ clone() [1/2]

template<typename T >
auto alloc::boxed::Box< T >::clone ( ) -> Self
inline

Creates a new Box by cloning the contained value.

Returns
A new Box with a cloned copy of the value.

◆ clone() [2/2]

template<typename T >
auto alloc::boxed::Box< T >::clone ( ) -> Self
inline

Creates a new Box by cloning all elements of the contained array.

Returns
A new Box owning a cloned copy of the array.

◆ clone_from()

template<typename T >
void alloc::boxed::Box< T >::clone_from ( Self & source)
inline

Replaces the contents of this Box with a clone of the source.

Parameters
sourceThe Box to clone from.

◆ from_raw()

template<typename T >
static constexpr Box alloc::boxed::Box< T >::from_raw ( mut_ptr< T > raw)
inlinestaticconstexprnoexcept

Constructs a Box from a raw mutable pointer.

Parameters
rawThe raw pointer that was previously obtained from into_raw.
Returns
A Box that takes ownership of the pointed-to value.

◆ get()

template<typename T >
auto alloc::boxed::Box< T >::get ( ) -> mut_ptr<T>::value_type*
inlineconstexprnoexcept

Returns a raw pointer to the contained value.

Returns
A raw pointer to the heap-allocated value.

◆ into_raw()

template<typename T >
auto alloc::boxed::Box< T >::into_raw ( ) && -> mut_ptr<T>
inlineconstexprnoexcept

Consumes the Box, returning the wrapped raw pointer without deallocating.

Returns
A mutable pointer to the heap-allocated value.

◆ make() [1/2]

template<typename T >
template<typename... Args>
requires Impled<T, Sized>
static auto alloc::boxed::Box< T >::make ( Args &&... args) -> Box
inlinestatic

Allocates memory on the heap and constructs T in place with the given arguments.

Template Parameters
ArgsThe constructor argument types.
Parameters
argsThe arguments forwarded to the constructor of T.
Returns
A Box owning the newly allocated value.

◆ make() [2/2]

template<typename T >
template<typename U >
static auto alloc::boxed::Box< T >::make ( U && in) -> Box requires(! Impled<T, Sized> && mtp::dyn_traits<T>::template Impled<U>)
inlinestatic

Allocates memory on the heap for a dynamically-sized trait object.

Template Parameters
UThe concrete type that implements the trait T.
Parameters
inThe value to box as a trait object.
Returns
A Box owning the trait object.

◆ pin()

template<typename T >
static auto alloc::boxed::Box< T >::pin ( T && in) -> Pin<Box>
inlinestatic

Constructs a new Pin<Box<T>> by moving the value onto the heap.

Parameters
inThe value to pin on the heap.
Returns
A pinned Box owning the value.

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