pub struct NodePtr<Header, U>where
U: ?Sized,{ /* private fields */ }
Expand description
A pointer to a node with a header and a possibly unsized value.
Implementations§
Source§impl<Header, U> NodePtr<Header, U>
impl<Header, U> NodePtr<Header, U>
Sourcepub const fn to_header_opaque(self) -> HeaderOpaqueNodePtr<U>
pub const fn to_header_opaque(self) -> HeaderOpaqueNodePtr<U>
Create a node pointer with an abstracted header type.
This is useful if you want to expose node pointers without exposing the header type.
Sourcepub fn header_ptr(self) -> NonNull<Header>
pub fn header_ptr(self) -> NonNull<Header>
Get the pointer to the node’s header.
Sourcepub const fn value_ptr(self) -> NonNull<()>
pub const fn value_ptr(self) -> NonNull<()>
Get the pointer to the node’s value.
This does not include any metadata.
See Self::data_ptr
for a pointer with metadata.
Sourcepub const unsafe fn from_value_ptr(ptr: NonNull<()>) -> Self
pub const unsafe fn from_value_ptr(ptr: NonNull<()>) -> Self
Get a node back from its value pointer.
§Safety
The value pointer must have come from a call to Self::value_ptr
.
Sourcepub unsafe fn try_allocate_with_layout_in<A>(
metadata: <U as Pointee>::Metadata,
value_layout: Layout,
allocator: A,
) -> Result<Self, AllocateError>where
A: Allocator,
pub unsafe fn try_allocate_with_layout_in<A>(
metadata: <U as Pointee>::Metadata,
value_layout: Layout,
allocator: A,
) -> Result<Self, AllocateError>where
A: Allocator,
Attempts to allocate a node with the given value layout and metadata in the given allocator.
Using this function is not recommended! Try to use one of the other allocation functions first.
The returned node’s value pointer will be valid for writes within the size of the value_layout
.
§Safety
metadata
must be valid for value_layout
.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::extend
, this will return an AllocateError
.
Sourcepub unsafe fn try_allocate_in<A>(
metadata: <U as Pointee>::Metadata,
allocator: A,
) -> Result<Self, AllocateError>where
A: Allocator,
pub unsafe fn try_allocate_in<A>(
metadata: <U as Pointee>::Metadata,
allocator: A,
) -> Result<Self, AllocateError>where
A: Allocator,
Attempts to allocate a node with the given metadata in the given allocator.
§Safety
metadata
must be valid under the safety conditions for Layout::for_value_raw
.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::extend
, this will return an AllocateError
.
Sourcepub fn try_allocate_unsize_in<A, T>(allocator: A) -> Result<Self, AllocateError>
pub fn try_allocate_unsize_in<A, T>(allocator: A) -> Result<Self, AllocateError>
Attempts to allocate a node with value layout of T
but metadata of &T as &U
in the given allocator.
The resulting node’s value pointer will be valid for writes of T
.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::extend
, this will return an AllocateError
.
Sourcepub unsafe fn try_allocate_with_layout(
metadata: <U as Pointee>::Metadata,
value_layout: Layout,
) -> Result<Self, AllocateError>
pub unsafe fn try_allocate_with_layout( metadata: <U as Pointee>::Metadata, value_layout: Layout, ) -> Result<Self, AllocateError>
Attempts to allocate a node with the given value layout and metadata.
Using this function is not recommended! Try to use one of the other allocation functions first.
§Safety
metadata
must be valid for value_layout
.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::extend
, this will return an AllocateError
.
Sourcepub unsafe fn try_allocate(
metadata: <U as Pointee>::Metadata,
) -> Result<Self, AllocateError>
pub unsafe fn try_allocate( metadata: <U as Pointee>::Metadata, ) -> Result<Self, AllocateError>
Attempts to allocate a node with the given metadata.
§Safety
metadata
must be valid under the safety conditions for Layout::for_value_raw
.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::extend
, this will return an AllocateError
.
Sourcepub fn try_allocate_unsize<T>() -> Result<Self, AllocateError>where
T: Unsize<U>,
pub fn try_allocate_unsize<T>() -> Result<Self, AllocateError>where
T: Unsize<U>,
Attempts to allocate a node with value layout of T
but metadata of &T as &U
.
The resulting node’s value pointer will be valid for writes of T
.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::extend
, this will return an AllocateError
.
Sourcepub unsafe fn allocate_with_layout_in<A>(
metadata: <U as Pointee>::Metadata,
value_layout: Layout,
allocator: A,
) -> Selfwhere
A: Allocator,
pub unsafe fn allocate_with_layout_in<A>(
metadata: <U as Pointee>::Metadata,
value_layout: Layout,
allocator: A,
) -> Selfwhere
A: Allocator,
Allocates a node with the given value layout and metadata in the given allocator.
Using this function is not recommended! Try to use one of the other allocation functions first.
§Safety
metadata
must be valid for value_layout
.
Sourcepub unsafe fn allocate_in<A>(
metadata: <U as Pointee>::Metadata,
allocator: A,
) -> Selfwhere
A: Allocator,
pub unsafe fn allocate_in<A>(
metadata: <U as Pointee>::Metadata,
allocator: A,
) -> Selfwhere
A: Allocator,
Allocates a node with the given metadata in the given allocator.
§Safety
metadata
must be valid under the safety conditions for Layout::for_value_raw
.
Sourcepub fn allocate_unsize_in<A, T>(allocator: A) -> Self
pub fn allocate_unsize_in<A, T>(allocator: A) -> Self
Allocates a node with value layout of T
but metadata of &T as &U
in the given allocator.
The resulting node’s value pointer will be valid for writes of T
.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::extend
, this will return an AllocateError
.
Sourcepub unsafe fn allocate_with_layout(
metadata: <U as Pointee>::Metadata,
value_layout: Layout,
) -> Self
pub unsafe fn allocate_with_layout( metadata: <U as Pointee>::Metadata, value_layout: Layout, ) -> Self
Allocates a node with the given value layout and metadata.
Using this function is not recommended! Try to use one of the other allocation functions first.
§Safety
metadata
must be valid for value_layout
.
Sourcepub unsafe fn allocate(metadata: <U as Pointee>::Metadata) -> Self
pub unsafe fn allocate(metadata: <U as Pointee>::Metadata) -> Self
Allocates a node with the given metadata.
§Safety
metadata
must be valid under the safety conditions for Layout::for_value_raw
.
Sourcepub fn allocate_unsize<T>() -> Selfwhere
T: Unsize<U>,
pub fn allocate_unsize<T>() -> Selfwhere
T: Unsize<U>,
Allocates a node with value layout of T
but metadata of &T as &U
.
The resulting node’s value pointer will be valid for writes of T
.
Sourcepub unsafe fn deallocate<A>(self, allocator: A)where
A: Allocator,
pub unsafe fn deallocate<A>(self, allocator: A)where
A: Allocator,
Deallocates the node.
Note that this does not drop the contined value.
§Safety
- The node must not have been deallocated already.
- The node must not be used at all after this call; this includes aliases!
allocator
must be the same allocator used to allocate the node.- This must not be called whilst there is a living reference to the node’s data.
Sourcepub unsafe fn deallocate_global(self)
pub unsafe fn deallocate_global(self)
Deallocates the node.
Note that this does not drop the contined value.
§Safety
- The node must not have been deallocated already.
- The node must not be used at all after this call; this includes aliases!
- The node must have been allocated using the global allocator.
- This must not be called whilst there is a living reference to the node’s data.
Source§impl<Header, T> NodePtr<Header, T>
impl<Header, T> NodePtr<Header, T>
Sourcepub fn try_allocate_sized_in<A>(allocator: A) -> Result<Self, AllocateError>where
A: Allocator,
pub fn try_allocate_sized_in<A>(allocator: A) -> Result<Self, AllocateError>where
A: Allocator,
Attempts to allocate a node for a value of type T
in the given allocator.
The returned node’s value pointer is valid for writes of T
.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::extend
, this will return an AllocateError
.
Sourcepub fn try_allocate_sized() -> Result<Self, AllocateError>
pub fn try_allocate_sized() -> Result<Self, AllocateError>
Attempts to allocate a node for a value of type T
.
The returned node’s value pointer is valid for writes of T
.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::extend
, this will return an AllocateError
.
Sourcepub fn allocate_sized_in<A>(allocator: A) -> Selfwhere
A: Allocator,
pub fn allocate_sized_in<A>(allocator: A) -> Selfwhere
A: Allocator,
Allocates a node for a value of type T
in the given allocator.
The returned node’s value pointer is valid for writes of T
.
Sourcepub fn allocate_sized() -> Self
pub fn allocate_sized() -> Self
Allocates a node for a value of type T
.
The returned node’s value pointer is valid for writes of T
.
Source§impl<Header, T> NodePtr<Header, [T]>
impl<Header, T> NodePtr<Header, [T]>
Sourcepub fn try_allocate_array_in<A>(
length: usize,
allocator: A,
) -> Result<Self, AllocateError>where
A: Allocator,
pub fn try_allocate_array_in<A>(
length: usize,
allocator: A,
) -> Result<Self, AllocateError>where
A: Allocator,
Attempts to allocate an array of T
with the given length in the given allocator.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::array
, this will return an AllocateError
.
Sourcepub fn try_allocate_array(length: usize) -> Result<Self, AllocateError>
pub fn try_allocate_array(length: usize) -> Result<Self, AllocateError>
Attempts to allocate an array of T
with the given length.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::array
, this will return an AllocateError
.
Sourcepub fn allocate_array_in<A>(length: usize, allocator: A) -> Selfwhere
A: Allocator,
pub fn allocate_array_in<A>(length: usize, allocator: A) -> Selfwhere
A: Allocator,
Allocates an array of T
with the given length in the given allocator.
Sourcepub fn allocate_array(length: usize) -> Self
pub fn allocate_array(length: usize) -> Self
Allocates an array of T
with the given length.
Source§impl<Header> NodePtr<Header, str>
impl<Header> NodePtr<Header, str>
Sourcepub fn try_allocate_string_in<A>(
length: usize,
allocator: A,
) -> Result<Self, AllocateError>where
A: Allocator,
pub fn try_allocate_string_in<A>(
length: usize,
allocator: A,
) -> Result<Self, AllocateError>where
A: Allocator,
Attempts to allocate a string with the given length in the given allocator.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::array
, this will return an AllocateError
.
Sourcepub fn try_allocate_string(length: usize) -> Result<Self, AllocateError>
pub fn try_allocate_string(length: usize) -> Result<Self, AllocateError>
Attempts to allocate a string with the given length.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::array
, this will return an AllocateError
.
Sourcepub fn allocate_string_in<A>(length: usize, allocator: A) -> Selfwhere
A: Allocator,
pub fn allocate_string_in<A>(length: usize, allocator: A) -> Selfwhere
A: Allocator,
Allocates a string with the given length in the given allocator.
Sourcepub fn allocate_string(length: usize) -> Self
pub fn allocate_string(length: usize) -> Self
Allocates a string with the given length.