pub struct MaybeUninitNode<'a, U, A = Global>{ /* 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:
- Allocate an uninitialised node using either a
DynListor aCursorMut - Initialise the node
- Call
Self::insert
Implementations§
Source§impl<'a, U, A> MaybeUninitNode<'a, U, A>
impl<'a, U, A> MaybeUninitNode<'a, U, A>
Sourcepub unsafe fn drop_in_place(&mut self)
pub unsafe fn drop_in_place(&mut self)
Sourcepub unsafe fn insert(self)
pub unsafe fn insert(self)
Inserts the node into the list.
§Safety
The value must:
- have been initialised
- be valid for
Uwith the metadata the node was created with - not have been dropped
- not have been copied unless it is
Copy
Examples found in repository?
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:?}");
}Sourcepub unsafe fn try_take_boxed(self) -> Result<Box<U, A>, AllocError>where
A: Clone,
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
Uwith 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§impl<T, A> MaybeUninitNode<'_, T, A>where
A: Allocator,
impl<T, A> MaybeUninitNode<'_, T, A>where
A: Allocator,
Sourcepub fn as_ref(&self) -> &MaybeUninit<T>
pub fn as_ref(&self) -> &MaybeUninit<T>
Gets a reference to the contained value.
Sourcepub fn as_mut(&mut self) -> &mut MaybeUninit<T>
pub fn as_mut(&mut self) -> &mut MaybeUninit<T>
Gets a mutable reference to the contained value.
Source§impl<T, A> MaybeUninitNode<'_, [T], A>where
A: Allocator,
impl<T, A> MaybeUninitNode<'_, [T], A>where
A: Allocator,
Sourcepub fn as_slice(&self) -> &[MaybeUninit<T>]
pub fn as_slice(&self) -> &[MaybeUninit<T>]
Gets a reference to the contained slice.
Sourcepub fn as_slice_mut(&mut self) -> &mut [MaybeUninit<T>]
pub fn as_slice_mut(&mut self) -> &mut [MaybeUninit<T>]
Gets a mutable reference to the contained slice.
Examples found in repository?
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:?}");
}Sourcepub fn copy_from_slice(&mut self, src: &[T])where
T: Copy,
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.
Sourcepub fn clone_from_slice(&mut self, src: &[T])where
T: Clone,
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,
impl<A> MaybeUninitNode<'_, str, A>where
A: Allocator,
Sourcepub fn as_bytes(&self) -> &[MaybeUninit<u8>]
pub fn as_bytes(&self) -> &[MaybeUninit<u8>]
Gets a reference to the contained string as a byte slice.
Sourcepub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]
pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]
Gets a mutable reference to the contained string as a byte slice.
Sourcepub fn copy_from_str(&mut self, src: &str)
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.