pub struct DynList<U, A = Global>{ /* private fields */ }Expand description
A doubly-linked list that allows nodes with dynamically sized types.
Implementations§
Source§impl<U, A> DynList<U, A>
impl<U, A> DynList<U, A>
Sourcepub fn extend_unsize<T>(&mut self, iter: T)
pub fn extend_unsize<T>(&mut self, iter: T)
Extends the list with the contents of iter after unsizing them.
Sourcepub fn from_iter_unsize_in<T>(iter: T, allocator: A) -> Self
pub fn from_iter_unsize_in<T>(iter: T, allocator: A) -> Self
Creates a DynList from the contents of iter in allocator after unsizing the elements.
Source§impl<U> DynList<U>where
U: ?Sized,
impl<U> DynList<U>where
U: ?Sized,
Sourcepub fn from_iter_unsize<T>(iter: T) -> Self
pub fn from_iter_unsize<T>(iter: T) -> Self
Creates a DynList from the contents of iter after unsizing the elements.
Source§impl<T, A> DynList<T, A>where
A: Allocator,
impl<T, A> DynList<T, A>where
A: Allocator,
Sourcepub fn try_allocate_uninit_sized_front(
&mut self,
) -> Result<MaybeUninitNode<'_, T, A>, AllocError>
pub fn try_allocate_uninit_sized_front( &mut self, ) -> Result<MaybeUninitNode<'_, T, A>, AllocError>
Attempts to allocate an uninitialised, sized node at the front of the list.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn try_allocate_uninit_sized_back(
&mut self,
) -> Result<MaybeUninitNode<'_, T, A>, AllocError>
pub fn try_allocate_uninit_sized_back( &mut self, ) -> Result<MaybeUninitNode<'_, T, A>, AllocError>
Attempts to allocate an uninitialised, sized node at the back of the list.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn allocate_uninit_sized_front(&mut self) -> MaybeUninitNode<'_, T, A>
pub fn allocate_uninit_sized_front(&mut self) -> MaybeUninitNode<'_, T, A>
Allocates an uninitialised, sized node at the front of the list.
Sourcepub fn allocate_uninit_sized_back(&mut self) -> MaybeUninitNode<'_, T, A>
pub fn allocate_uninit_sized_back(&mut self) -> MaybeUninitNode<'_, T, A>
Allocates an uninitialised, sized node at the back of the list.
Sourcepub fn try_push_front(&mut self, value: T) -> Result<(), AllocError>
pub fn try_push_front(&mut self, value: T) -> Result<(), AllocError>
Attempts to push value to the front of the list.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn try_push_back(&mut self, value: T) -> Result<(), AllocError>
pub fn try_push_back(&mut self, value: T) -> Result<(), AllocError>
Attempts to push value to the back of the list.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn push_front(&mut self, value: T)
pub fn push_front(&mut self, value: T)
Pushes value to the front of the list.
Sourcepub fn push_back(&mut self, value: T)
pub fn push_back(&mut self, value: T)
Pushes value to the back of the list.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let mut list = DynList::<u8>::new();
list.push_back(0);
list.push_back(1);
list.push_back(2);
let mut cursor = list.cursor_front_mut();
cursor.move_next();
cursor.insert_before(100);
println!("{list:?}");
}Source§impl<T, A> DynList<[T], A>where
A: Allocator,
impl<T, A> DynList<[T], A>where
A: Allocator,
Sourcepub fn try_allocate_uninit_slice_front(
&mut self,
length: usize,
) -> Result<MaybeUninitNode<'_, [T], A>, AllocError>
pub fn try_allocate_uninit_slice_front( &mut self, length: usize, ) -> Result<MaybeUninitNode<'_, [T], A>, AllocError>
Attempts to allocate an uninitialised slice node at the front of the list.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::array, this will return an AllocError.
Sourcepub fn try_allocate_uninit_slice_back(
&mut self,
length: usize,
) -> Result<MaybeUninitNode<'_, [T], A>, AllocError>
pub fn try_allocate_uninit_slice_back( &mut self, length: usize, ) -> Result<MaybeUninitNode<'_, [T], A>, AllocError>
Attempts to allocate an uninitialised slice node at the back of the list.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::array, this will return an AllocError.
Sourcepub fn allocate_uninit_slice_front(
&mut self,
length: usize,
) -> MaybeUninitNode<'_, [T], A>
pub fn allocate_uninit_slice_front( &mut self, length: usize, ) -> MaybeUninitNode<'_, [T], A>
Allocates an uninitialised slice node at the front of the list.
Sourcepub fn allocate_uninit_slice_back(
&mut self,
length: usize,
) -> MaybeUninitNode<'_, [T], A>
pub fn allocate_uninit_slice_back( &mut self, length: usize, ) -> MaybeUninitNode<'_, [T], A>
Allocates an uninitialised slice node at the back of the list.
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 try_push_front_copy_slice(&mut self, src: &[T]) -> Result<(), AllocError>where
T: Copy,
pub fn try_push_front_copy_slice(&mut self, src: &[T]) -> Result<(), AllocError>where
T: Copy,
Attempts to copy the slice src and push it to the front of the list.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn try_push_back_copy_slice(&mut self, src: &[T]) -> Result<(), AllocError>where
T: Copy,
pub fn try_push_back_copy_slice(&mut self, src: &[T]) -> Result<(), AllocError>where
T: Copy,
Attempts to copy the slice src and push it to the back of the list.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn push_front_copy_slice(&mut self, src: &[T])where
T: Copy,
pub fn push_front_copy_slice(&mut self, src: &[T])where
T: Copy,
Copies the slice src and pushes it to the front of the list.
Sourcepub fn push_back_copy_slice(&mut self, src: &[T])where
T: Copy,
pub fn push_back_copy_slice(&mut self, src: &[T])where
T: Copy,
Copies the slice src and pushes it to the back of the list.
Sourcepub fn try_push_front_clone_slice(
&mut self,
src: &[T],
) -> Result<(), AllocError>where
T: Clone,
pub fn try_push_front_clone_slice(
&mut self,
src: &[T],
) -> Result<(), AllocError>where
T: Clone,
Attempts to clone the slice src and push it to the front of the list.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn try_push_back_clone_slice(&mut self, src: &[T]) -> Result<(), AllocError>where
T: Clone,
pub fn try_push_back_clone_slice(&mut self, src: &[T]) -> Result<(), AllocError>where
T: Clone,
Attempts to clone the slice src and push it to the back of the list.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn push_front_clone_slice(&mut self, src: &[T])where
T: Clone,
pub fn push_front_clone_slice(&mut self, src: &[T])where
T: Clone,
Clones the slice src and pushes it to the front of the list.
Sourcepub fn push_back_clone_slice(&mut self, src: &[T])where
T: Clone,
pub fn push_back_clone_slice(&mut self, src: &[T])where
T: Clone,
Clones the slice src and pushes it to the back of the list.
Source§impl<A> DynList<str, A>where
A: Allocator,
impl<A> DynList<str, A>where
A: Allocator,
Sourcepub unsafe fn from_utf8_unchecked(bytes: DynList<[u8], A>) -> Self
pub unsafe fn from_utf8_unchecked(bytes: DynList<[u8], A>) -> Self
Converts the list of byte slices to a list of string slices without checking that the slices contain valid UTF-8.
§Safety
All byte slices in the list must be valid UTF-8.
For more information, see str::from_utf8_unchecked.
Sourcepub fn into_bytes(self) -> DynList<[u8], A>
pub fn into_bytes(self) -> DynList<[u8], A>
Converts the list of string slices to a list of byte slices.
Sourcepub fn try_allocate_uninit_str_front(
&mut self,
length: usize,
) -> Result<MaybeUninitNode<'_, str, A>, AllocError>
pub fn try_allocate_uninit_str_front( &mut self, length: usize, ) -> Result<MaybeUninitNode<'_, str, A>, AllocError>
Attempts to allocate an uninitialised str node at the front of the list.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::array, this will return an AllocError.
Sourcepub fn try_allocate_uninit_str_back(
&mut self,
length: usize,
) -> Result<MaybeUninitNode<'_, str, A>, AllocError>
pub fn try_allocate_uninit_str_back( &mut self, length: usize, ) -> Result<MaybeUninitNode<'_, str, A>, AllocError>
Attempts to allocate an uninitialised str node at the back of the list.
§Errors
If allocation fails, or an arithmetic overflow occours in Layout::array, this will return an AllocError.
Sourcepub fn allocate_uninit_str_front(
&mut self,
length: usize,
) -> MaybeUninitNode<'_, str, A>
pub fn allocate_uninit_str_front( &mut self, length: usize, ) -> MaybeUninitNode<'_, str, A>
Allocates an uninitialised str node at the front of the list.
Sourcepub fn allocate_uninit_str_back(
&mut self,
length: usize,
) -> MaybeUninitNode<'_, str, A>
pub fn allocate_uninit_str_back( &mut self, length: usize, ) -> MaybeUninitNode<'_, str, A>
Allocates an uninitialised str node at the back of the list.
Sourcepub fn try_push_front_copy_str(&mut self, src: &str) -> Result<(), AllocError>
pub fn try_push_front_copy_str(&mut self, src: &str) -> Result<(), AllocError>
Attempts to copy the string slice src and push it to the front of the list.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn try_push_back_copy_str(&mut self, src: &str) -> Result<(), AllocError>
pub fn try_push_back_copy_str(&mut self, src: &str) -> Result<(), AllocError>
Attempts to copy the string slice src and push it to the back of the list.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn push_front_copy_str(&mut self, src: &str)
pub fn push_front_copy_str(&mut self, src: &str)
Copies the string slice src and pushes it to the front of the list.
Sourcepub fn push_back_copy_str(&mut self, src: &str)
pub fn push_back_copy_str(&mut self, src: &str)
Copies the string slice src and pushes it to the back of the list.
Source§impl<U, A> DynList<U, A>
impl<U, A> DynList<U, A>
Sourcepub fn into_raw_parts(self) -> (Option<(NonNull<()>, NonNull<()>)>, A)
pub fn into_raw_parts(self) -> (Option<(NonNull<()>, NonNull<()>)>, A)
Decomposes the DynList into pointers to the head and tail (if not empty), and the allocator.
Sourcepub unsafe fn from_raw_parts(
ends: Option<(NonNull<()>, NonNull<()>)>,
allocator: A,
) -> Self
pub unsafe fn from_raw_parts( ends: Option<(NonNull<()>, NonNull<()>)>, allocator: A, ) -> Self
Creates a DynList from pointers to the head and tail (if not empty), and an allocator.
§Safety
- If the
endsare notNone, they must have come from a call toSelf::into_raw_partswith aUwith the same layout and invariants. allocatormust be valid for the nodes in the list.
Sourcepub unsafe fn try_allocate_uninit_front(
&mut self,
metadata: <U as Pointee>::Metadata,
) -> Result<MaybeUninitNode<'_, U, A>, AllocError>
pub unsafe fn try_allocate_uninit_front( &mut self, metadata: <U as Pointee>::Metadata, ) -> Result<MaybeUninitNode<'_, U, A>, AllocError>
Attempts to allocate an uninitialised node at the front of the list.
§Safety
The metadata must be valid under the safety conditions for Layout::for_value_raw.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub unsafe fn try_allocate_uninit_back(
&mut self,
metadata: <U as Pointee>::Metadata,
) -> Result<MaybeUninitNode<'_, U, A>, AllocError>
pub unsafe fn try_allocate_uninit_back( &mut self, metadata: <U as Pointee>::Metadata, ) -> Result<MaybeUninitNode<'_, U, A>, AllocError>
Attempts to allocate an uninitialised node at the back of the list.
§Safety
The metadata must be valid under the safety conditions for Layout::for_value_raw.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub unsafe fn allocate_uninit_front(
&mut self,
metadata: <U as Pointee>::Metadata,
) -> MaybeUninitNode<'_, U, A>
pub unsafe fn allocate_uninit_front( &mut self, metadata: <U as Pointee>::Metadata, ) -> MaybeUninitNode<'_, U, A>
Allocates an uninitialised node at the front of the list.
§Safety
The metadata must be valid under the safety conditions for Layout::for_value_raw.
Sourcepub unsafe fn allocate_uninit_back(
&mut self,
metadata: <U as Pointee>::Metadata,
) -> MaybeUninitNode<'_, U, A>
pub unsafe fn allocate_uninit_back( &mut self, metadata: <U as Pointee>::Metadata, ) -> MaybeUninitNode<'_, U, A>
Allocates an uninitialised node at the tail of the list.
§Safety
The metadata must be valid under the safety conditions for Layout::for_value_raw.
Sourcepub fn try_push_front_unsize<T>(&mut self, value: T) -> Result<(), AllocError>where
T: Unsize<U>,
pub fn try_push_front_unsize<T>(&mut self, value: T) -> Result<(), AllocError>where
T: Unsize<U>,
Attempts to push value to the front of the list and unsize it to U.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn try_push_back_unsize<T>(&mut self, value: T) -> Result<(), AllocError>where
T: Unsize<U>,
pub fn try_push_back_unsize<T>(&mut self, value: T) -> Result<(), AllocError>where
T: Unsize<U>,
Attempts to push value to the back of the list and unsize it to U.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn push_front_unsize<T>(&mut self, value: T)where
T: Unsize<U>,
pub fn push_front_unsize<T>(&mut self, value: T)where
T: Unsize<U>,
Pushes value to the front of the list and unsizes it to U.
§Examples
let mut list = DynList::<dyn Debug>::new();
list.push_front_unsize("Hello, World!");Sourcepub fn push_back_unsize<T>(&mut self, value: T)where
T: Unsize<U>,
pub fn push_back_unsize<T>(&mut self, value: T)where
T: Unsize<U>,
Pushes value to the back of the list and unsizes it to U.
§Examples
let mut list = DynList::<dyn Debug>::new();
list.push_back_unsize("Hello, World!");Examples found in repository?
More examples
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 pop_front_node(&mut self) -> Option<MaybeUninitNode<'_, U, A>>
pub fn pop_front_node(&mut self) -> Option<MaybeUninitNode<'_, U, A>>
Removes the front node of the list.
If you do not want a MaybeUninitNode, this is the wrong function!
Sourcepub fn pop_back_node(&mut self) -> Option<MaybeUninitNode<'_, U, A>>
pub fn pop_back_node(&mut self) -> Option<MaybeUninitNode<'_, U, A>>
Removes the back node of the list.
If you do not want a MaybeUninitNode, this is the wrong function!
Sourcepub fn delete_front(&mut self) -> bool
pub fn delete_front(&mut self) -> bool
Sourcepub fn delete_back(&mut self) -> bool
pub fn delete_back(&mut self) -> bool
Sourcepub fn try_pop_front_boxed(&mut self) -> Option<Result<Box<U, A>, AllocError>>where
A: Clone,
pub fn try_pop_front_boxed(&mut self) -> Option<Result<Box<U, A>, AllocError>>where
A: Clone,
Attempts to remove the front node and return it in a Box.
§Errors
If allocation fails, this will return an AllocError.
The node will be deleted.
Sourcepub fn try_pop_back_boxed(&mut self) -> Option<Result<Box<U, A>, AllocError>>where
A: Clone,
pub fn try_pop_back_boxed(&mut self) -> Option<Result<Box<U, A>, AllocError>>where
A: Clone,
Attempts to remove the back node and return it in a Box.
§Errors
If allocation fails, this will return an AllocError.
The node will be deleted.
Sourcepub fn pop_front_boxed(&mut self) -> Option<Box<U, A>>where
A: Clone,
pub fn pop_front_boxed(&mut self) -> Option<Box<U, A>>where
A: Clone,
Removes the front node and returns it in a Box.
let mut list = DynList::<dyn PartialEq<u8>>::new();
list.push_back_unsize(5);
assert!(&*list.pop_front_boxed().unwrap() == &5_u8);Sourcepub fn pop_back_boxed(&mut self) -> Option<Box<U, A>>where
A: Clone,
pub fn pop_back_boxed(&mut self) -> Option<Box<U, A>>where
A: Clone,
Removes the back node and returns it in a Box.
let mut list = DynList::<dyn PartialEq<u8>>::new();
list.push_back_unsize(5);
assert!(&*list.pop_back_boxed().unwrap() == &5_u8);Sourcepub const fn cursor_front(&self) -> Cursor<'_, U, A>
pub const fn cursor_front(&self) -> Cursor<'_, U, A>
Creates a Cursor at the front of the list.
If the list is empty, this will point to the “ghost” element.
Sourcepub const fn cursor_back(&self) -> Cursor<'_, U, A>
pub const fn cursor_back(&self) -> Cursor<'_, U, A>
Creates a Cursor at the back of the list.
If the list is empty, this will point to the “ghost” element.
Sourcepub const fn cursor_front_mut(&mut self) -> CursorMut<'_, U, A>
pub const fn cursor_front_mut(&mut self) -> CursorMut<'_, U, A>
Creates a CursorMut at the front of the list that can mutate the list.
If the list is empty, this will point to the “ghost” element.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let mut list = DynList::<u8>::new();
list.push_back(0);
list.push_back(1);
list.push_back(2);
let mut cursor = list.cursor_front_mut();
cursor.move_next();
cursor.insert_before(100);
println!("{list:?}");
}Sourcepub const fn cursor_back_mut(&mut self) -> CursorMut<'_, U, A>
pub const fn cursor_back_mut(&mut self) -> CursorMut<'_, U, A>
Creates a CursorMut at the back of the list that can mutate the list.
If the list is empty, this will point to the “ghost” element.
Sourcepub const fn iter(&self) -> Iter<'_, U> ⓘ
pub const fn iter(&self) -> Iter<'_, U> ⓘ
Creates an iterator over references to the items in the list.
Sourcepub const fn iter_mut(&mut self) -> IterMut<'_, U> ⓘ
pub const fn iter_mut(&mut self) -> IterMut<'_, U> ⓘ
Creates an iterator over mutable references to the items in the list.
Sourcepub const fn into_iter_boxed(self) -> IntoIterBoxed<U, A> ⓘwhere
A: Clone,
pub const fn into_iter_boxed(self) -> IntoIterBoxed<U, A> ⓘwhere
A: Clone,
Converts the list to an iterator that yields the elements in boxes.
Sourcepub fn try_clone_in<A2>(
&self,
allocator: A2,
) -> Result<DynList<U, A2>, AllocError>where
U: CloneToUninit,
A2: Allocator,
pub fn try_clone_in<A2>(
&self,
allocator: A2,
) -> Result<DynList<U, A2>, AllocError>where
U: CloneToUninit,
A2: Allocator,
Attempts to clone the list into another allocator.
§Errors
If allocation fails, this will return an AllocError.
Sourcepub fn clone_in<A2>(&self, allocator: A2) -> DynList<U, A2>where
U: CloneToUninit,
A2: Allocator,
pub fn clone_in<A2>(&self, allocator: A2) -> DynList<U, A2>where
U: CloneToUninit,
A2: Allocator,
Clones the list into another allocator.
Source§impl<U> DynList<U>where
U: ?Sized,
impl<U> DynList<U>where
U: ?Sized,
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an empty DynList.
Examples found in repository?
More examples
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let mut list = DynList::<u8>::new();
list.push_back(0);
list.push_back(1);
list.push_back(2);
let mut cursor = list.cursor_front_mut();
cursor.move_next();
cursor.insert_before(100);
println!("{list:?}");
}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:?}");
}Trait Implementations§
Source§impl<'a, Item, A> Extend<&'a Item> for DynList<Item, A>
impl<'a, Item, A> Extend<&'a Item> for DynList<Item, A>
Source§fn extend<T: IntoIterator<Item = &'a Item>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a Item>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<Item, A> Extend<Item> for DynList<Item, A>where
A: Allocator,
impl<Item, A> Extend<Item> for DynList<Item, A>where
A: Allocator,
Source§fn extend<T: IntoIterator<Item = Item>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Item>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)