rstd 0.1.0
Loading...
Searching...
No Matches
rstd::ptr_::non_null::NonNull< T > Struct Template Referenceexport
module rstd.core

A non-null pointer type, analogous to Rust's NonNull<T>. More...

Public Member Functions

template<class U >
constexpr auto cast () const noexcept
 Casts this NonNull<T> to a NonNull<U>.
 
constexpr NonNull add (usize count) const noexcept
 Calculates the pointer offset by count elements forward.
 
constexpr NonNull sub (usize count) const noexcept
 Calculates the pointer offset by count elements backward.
 
constexpr NonNull offset (isize count) const noexcept
 Calculates the pointer offset by a signed count of elements.
 
constexpr NonNull byte_add (usize bytes) const noexcept
 Calculates the pointer offset by bytes bytes forward.
 
constexpr NonNull byte_sub (usize bytes) const noexcept
 Calculates the pointer offset by bytes bytes backward.
 

Static Public Member Functions

T: Sized
static auto without_provenance (num::nonzero::NonZero< usize > addr) noexcept -> NonNull< T >
 Creates a new NonNull from a non-zero address without provenance.
 
static auto dangling () noexcept -> NonNull< T >
 Creates a dangling but well-aligned NonNull pointer.
 

T: ?Sized

static constexpr auto make (pointer_t p) noexcept -> Option< NonNull >
 Creates a NonNull if the pointer is non-null, or None otherwise.
 
static constexpr auto make_unchecked (pointer_t p) noexcept -> NonNull
 Creates a NonNull without checking that the pointer is non-null.
 
constexpr auto as_ptr () const noexcept -> const_pointer_t
 Returns the inner pointer as a const pointer.
 
constexpr auto as_mut_ptr () const noexcept -> pointer_t
 Returns the inner pointer as a mutable pointer.
 
constexpr operator bool () const noexcept
 Returns true if the pointer is non-null.
 
constexpr auto as_ref () const noexcept
 Dereferences the pointer, returning an immutable reference.
 
constexpr auto as_mut () const noexcept
 Dereferences the pointer, returning a mutable reference.
 
constexpr auto as_raw_ptr () const noexcept
 Returns the underlying raw pointer.
 

Detailed Description

template<typename T>
struct rstd::ptr_::non_null::NonNull< T >

A non-null pointer type, analogous to Rust's NonNull<T>.

A non-null pointer type, guaranteed to never be null.

Template Parameters
TThe pointee type.

Member Function Documentation

◆ add()

template<typename T >
NonNull rstd::ptr_::non_null::NonNull< T >::add ( usize count) const
inlineconstexprnoexcept

Calculates the pointer offset by count elements forward.

Parameters
countNumber of elements to advance.
Returns
The offset NonNull pointer.

◆ byte_add()

template<typename T >
NonNull rstd::ptr_::non_null::NonNull< T >::byte_add ( usize bytes) const
inlineconstexprnoexcept

Calculates the pointer offset by bytes bytes forward.

Parameters
bytesNumber of bytes to advance.
Returns
The offset NonNull pointer.

◆ byte_sub()

template<typename T >
NonNull rstd::ptr_::non_null::NonNull< T >::byte_sub ( usize bytes) const
inlineconstexprnoexcept

Calculates the pointer offset by bytes bytes backward.

Parameters
bytesNumber of bytes to subtract.
Returns
The offset NonNull pointer.

◆ cast()

template<typename T >
template<class U >
auto rstd::ptr_::non_null::NonNull< T >::cast ( ) const
inlineconstexprnoexcept

Casts this NonNull<T> to a NonNull<U>.

Template Parameters
UThe target pointee type.

◆ dangling()

template<typename T >
static auto rstd::ptr_::non_null::NonNull< T >::dangling ( ) -> NonNull<T>
inlinestaticnoexcept

Creates a dangling but well-aligned NonNull pointer.

Returns
A NonNull pointer aligned to T that must not be dereferenced.

◆ make()

template<typename T >
static constexpr auto rstd::ptr_::non_null::NonNull< T >::make ( pointer_t p) -> Option<NonNull>
inlinestaticconstexprnoexcept

Creates a NonNull if the pointer is non-null, or None otherwise.

Parameters
pThe pointer to wrap.
Returns
Some(NonNull) if p is non-null, None otherwise.

◆ make_unchecked()

template<typename T >
static constexpr auto rstd::ptr_::non_null::NonNull< T >::make_unchecked ( pointer_t p) -> NonNull
inlinestaticconstexprnoexcept

Creates a NonNull without checking that the pointer is non-null.

Parameters
pThe pointer to wrap; must not be null.
Returns
A NonNull wrapping p.

◆ offset()

template<typename T >
NonNull rstd::ptr_::non_null::NonNull< T >::offset ( isize count) const
inlineconstexprnoexcept

Calculates the pointer offset by a signed count of elements.

Parameters
countSigned element offset (positive = forward, negative = backward).
Returns
The offset NonNull pointer.

◆ sub()

template<typename T >
NonNull rstd::ptr_::non_null::NonNull< T >::sub ( usize count) const
inlineconstexprnoexcept

Calculates the pointer offset by count elements backward.

Parameters
countNumber of elements to subtract.
Returns
The offset NonNull pointer.

◆ without_provenance()

template<typename T >
static auto rstd::ptr_::non_null::NonNull< T >::without_provenance ( num::nonzero::NonZero< usize > addr) -> NonNull<T>
inlinestaticnoexcept

Creates a new NonNull from a non-zero address without provenance.

Parameters
addrA non-zero address.
Returns
A NonNull pointer with the given address.

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