Struct NodePtr

Source
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>
where U: ?Sized, <U as Pointee>::Metadata: Copy,

Source

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.

Source

pub const unsafe fn metadata(self) -> <U as Pointee>::Metadata

Get the metadata of the node’s data.

§Safety

The node must have not been deallocated.

Source

pub fn header_ptr(self) -> NonNull<Header>

Get the pointer to the node’s header.

Source

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.

Source

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.

Source

pub const unsafe fn data_ptr(self) -> NonNull<U>

Get the pointer to the node’s data.

§Safety

The node must not have been deallocated.

Source

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.

Source

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.

Source

pub fn try_allocate_unsize_in<A, T>(allocator: A) -> Result<Self, AllocateError>
where A: Allocator, T: Unsize<U>,

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.

Source

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.

Source

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.

Source

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.

Source

pub unsafe fn allocate_with_layout_in<A>( metadata: <U as Pointee>::Metadata, value_layout: Layout, allocator: A, ) -> Self
where 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.

Source

pub unsafe fn allocate_in<A>( metadata: <U as Pointee>::Metadata, allocator: A, ) -> Self
where 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.

Source

pub fn allocate_unsize_in<A, T>(allocator: A) -> Self
where A: Allocator, T: Unsize<U>,

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.

Source

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.

Source

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.

Source

pub fn allocate_unsize<T>() -> Self
where 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.

Source

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.
Source

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>

Source

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.

Source

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.

Source

pub fn allocate_sized_in<A>(allocator: A) -> Self
where 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.

Source

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]>

Source

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.

Source

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.

Source

pub fn allocate_array_in<A>(length: usize, allocator: A) -> Self
where A: Allocator,

Allocates an array of T with the given length in the given allocator.

Source

pub fn allocate_array(length: usize) -> Self

Allocates an array of T with the given length.

Source§

impl<Header> NodePtr<Header, str>

Source

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.

Source

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.

Source

pub fn allocate_string_in<A>(length: usize, allocator: A) -> Self
where A: Allocator,

Allocates a string with the given length in the given allocator.

Source

pub fn allocate_string(length: usize) -> Self

Allocates a string with the given length.

Trait Implementations§

Source§

impl<Header, U> Clone for NodePtr<Header, U>
where U: ?Sized,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Header, U> Debug for NodePtr<Header, U>
where U: ?Sized,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Header, U> From<NodePtr<Header, U>> for HeaderOpaqueNodePtr<U>
where U: ?Sized,

Source§

fn from(value: NodePtr<Header, U>) -> Self

Converts to this type from the input type.
Source§

impl<Header, T> Ord for NodePtr<Header, T>
where T: ?Sized,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<Header, T> PartialEq<Option<NodePtr<Header, T>>> for NodePtr<Header, T>
where T: ?Sized,

Source§

fn eq(&self, other: &Option<Self>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Header, T> PartialEq for NodePtr<Header, T>
where T: ?Sized,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Header, T> PartialOrd for NodePtr<Header, T>
where T: ?Sized,

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Header, U> Pointer for NodePtr<Header, U>
where U: ?Sized,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Header, U> Copy for NodePtr<Header, U>
where U: ?Sized,

Source§

impl<Header, T> Eq for NodePtr<Header, T>
where T: ?Sized,

Auto Trait Implementations§

§

impl<Header, U> Freeze for NodePtr<Header, U>
where U: ?Sized,

§

impl<Header, U> RefUnwindSafe for NodePtr<Header, U>
where Header: RefUnwindSafe, U: RefUnwindSafe + ?Sized,

§

impl<Header, U> !Send for NodePtr<Header, U>

§

impl<Header, U> !Sync for NodePtr<Header, U>

§

impl<Header, U> Unpin for NodePtr<Header, U>
where U: ?Sized,

§

impl<Header, U> UnwindSafe for NodePtr<Header, U>
where Header: RefUnwindSafe, U: RefUnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.