dyn_list

Struct MaybeUninitNode

Source
pub struct MaybeUninitNode<'a, U, A = Global>
where U: ?Sized, A: Allocator,
{ /* private fields */ }
Expand description

A node with possibly uninitialised data.

These nodes sit outside of a DynList and have previous and next nodes in the list. Calling Self::insert inserts the node into the list.

To insert a new node:

  1. Allocate an uninitialised node using either a DynList or a CursorMut
  2. Initialise the node
  3. Call Self::insert

Implementations§

Source§

impl<'a, U, A> MaybeUninitNode<'a, U, A>
where U: ?Sized, A: Allocator,

Source

pub fn value_ptr(&self) -> NonNull<()>

Gets a pointer to the value with no metadata.

Source

pub fn as_ptr(&self) -> NonNull<U>

Gets a pointer to the value.

Source

pub unsafe fn drop_in_place(&mut self)

Drops the contained value.

Note that this does not deallocate the node.

§Safety

The value must:

  • have been initialised
  • be valid for U with the metadata the node was created with
  • not have been dropped
  • not have been copied unless it is Copy
Source

pub unsafe fn insert(self)

Inserts the node into the list.

§Safety

The value must:

  • have been initialised
  • be valid for U with the metadata the node was created with
  • not have been dropped
  • not have been copied unless it is Copy
Examples found in repository?
examples/slice.rs (line 19)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let mut list = DynList::<[u8]>::new();

    list.push_back_unsize([0, 1, 2, 3]);

    let s = "Hello";
    let mut node = list.allocate_uninit_slice_back(s.len());

    node.as_slice_mut()
        .iter_mut()
        .zip("Hello".bytes())
        .for_each(|(dst, src)| {
            dst.write(src);
        });

    unsafe { node.insert() };

    println!("{list:?}");
}
Source

pub unsafe fn try_take_boxed(self) -> Result<Box<U, A>, AllocError>
where A: Clone,

Attempts to move the value into a box and return it.

§Safety

The value must:

  • have been initialised
  • be valid for U with the metadata the node was created with
  • not have been dropped
  • not have been copied unless it is Copy
§Errors

If allocation fails, this will return an AllocError.

Source

pub unsafe fn take_boxed(self) -> Box<U, A>
where A: Clone,

Moves the value into a box and returns it.

§Safety

The value must:

  • have been initialised
  • be valid for U with the metadata the node was created with
  • not have been dropped
  • not have been copied unless it is Copy
Source§

impl<T, A> MaybeUninitNode<'_, T, A>
where A: Allocator,

Source

pub fn as_ref(&self) -> &MaybeUninit<T>

Gets a reference to the contained value.

Source

pub fn as_mut(&mut self) -> &mut MaybeUninit<T>

Gets a mutable reference to the contained value.

Source

pub unsafe fn take(self) -> T

Removes the contained value.

§Safety

The value must:

  • have been initialised
  • be valid for T
  • not have been dropped
  • not have been copied unless it is Copy
Source§

impl<T, A> MaybeUninitNode<'_, [T], A>
where A: Allocator,

Source

pub fn as_slice(&self) -> &[MaybeUninit<T>]

Gets a reference to the contained slice.

Source

pub fn as_slice_mut(&mut self) -> &mut [MaybeUninit<T>]

Gets a mutable reference to the contained slice.

Examples found in repository?
examples/slice.rs (line 12)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let mut list = DynList::<[u8]>::new();

    list.push_back_unsize([0, 1, 2, 3]);

    let s = "Hello";
    let mut node = list.allocate_uninit_slice_back(s.len());

    node.as_slice_mut()
        .iter_mut()
        .zip("Hello".bytes())
        .for_each(|(dst, src)| {
            dst.write(src);
        });

    unsafe { node.insert() };

    println!("{list:?}");
}
Source

pub fn copy_from_slice(&mut self, src: &[T])
where T: Copy,

Copies the slice src into the node.

Note that if src is shorter than the contained slice, some of the slice may not be initialised.

Source

pub fn clone_from_slice(&mut self, src: &[T])
where T: Clone,

Clones the slice src into the node.

Note that if src is shorter than the contained slice, some of the slice may not be initialised.

Source§

impl<A> MaybeUninitNode<'_, str, A>
where A: Allocator,

Source

pub fn as_bytes(&self) -> &[MaybeUninit<u8>]

Gets a reference to the contained string as a byte slice.

Source

pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]

Gets a mutable reference to the contained string as a byte slice.

Source

pub fn copy_from_str(&mut self, src: &str)

Copies the string slice src into the node.

Note that if src is shorter than the contained slice, some of the string slice may not be initialised.

Trait Implementations§

Source§

impl<T, A> AsMut<[MaybeUninit<T>]> for MaybeUninitNode<'_, [T], A>
where A: Allocator,

Source§

fn as_mut(&mut self) -> &mut [MaybeUninit<T>]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T, A> AsMut<MaybeUninit<T>> for MaybeUninitNode<'_, T, A>
where A: Allocator,

Source§

fn as_mut(&mut self) -> &mut MaybeUninit<T>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T, A> AsRef<[MaybeUninit<T>]> for MaybeUninitNode<'_, [T], A>
where A: Allocator,

Source§

fn as_ref(&self) -> &[MaybeUninit<T>]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, A> AsRef<MaybeUninit<T>> for MaybeUninitNode<'_, T, A>
where A: Allocator,

Source§

fn as_ref(&self) -> &MaybeUninit<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<U, A> Debug for MaybeUninitNode<'_, U, A>
where U: ?Sized, A: Allocator,

Source§

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

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

impl<U, A> Drop for MaybeUninitNode<'_, U, A>
where U: ?Sized, A: Allocator,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<U, A> Send for MaybeUninitNode<'_, U, A>
where U: ?Sized + Send, A: Allocator + Send,

Source§

impl<U, A> Sync for MaybeUninitNode<'_, U, A>
where U: ?Sized + Sync, A: Allocator + Sync,

Auto Trait Implementations§

§

impl<'a, U, A> Freeze for MaybeUninitNode<'a, U, A>
where U: ?Sized,

§

impl<'a, U, A> RefUnwindSafe for MaybeUninitNode<'a, U, A>

§

impl<'a, U, A> Unpin for MaybeUninitNode<'a, U, A>
where U: ?Sized,

§

impl<'a, U, A = Global> !UnwindSafe for MaybeUninitNode<'a, U, A>

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