Class Subspace :: sus :: ptr :: NonNull
A pointer wrapper which holds a never-null pointer.
A NonNull
can not be implicitly created from an array, as that would throw
away the length information. Explicitly cast to a pointer to use NonNull
with an array.
The NonNull
type is trivially copyable and moveable.
NonNull
satisifes the NeverValueField
, so
Option<NonNull<T>>
has the same size as NonNull
,
similar to Option<T&>
.
TODO: Make a NonNullArray type? https://godbolt.org/z/3vW3xsz5h
Static Methods
Constructs a NonNull<T>
from a reference to T
.
Satisfies the sus::construct::From<NonNull<T>, T&>
concept.
Constructs a NonNull<T>
from a pointer to T
.
Does not implicitly convert from an array. The caller must explicitly convert it to a pointer to throw away the length of the array.
Panics
The method will panic if the pointer t
is null.
sus::ptr::SameOrSubclassOf<U, T *>
Constructs a NonNull<T>
from a pointer to T
.
Does not implicitly convert from an array. The caller must explicitly convert it to a pointer to throw away the length of the array.
Safety
This method must not be called with a null pointer, or Undefined Behaviour results.
Methods
Returns a mutable reference to the pointee.
This method is only callable when the pointer is not const.
Returns a mutable pointer to the pointee.
This method is only callable when the pointer is not const.
Returns a const pointer to the pointee.
Returns a const reference to the pointee.
Cast the pointer of type T
in NonNull<T>
to a pointer of type U
and
return a NonNull<U>
.
This requires that T*
is a subclass of U*
. To perform a
downcast, like static_cast<U*> allows, use downcast()
.
Cast the pointer of type T
in NonNull<T>
to a pointer of type U
and
return a NonNull<U>
.
Safety
The pointee must be a U*
or this results in Undefined Behaviour.
Operators
Gives access to the object pointed to by NonNull.
Mutable access is only given is NonNull is not const and the pointer within is not const.