dyn_list

Struct DynList

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

A doubly-linked list that allows nodes with dynamically sized types.

Implementations§

Source§

impl<U, A> DynList<U, A>
where U: ?Sized, A: Allocator,

Source

pub fn extend_unsize<T>(&mut self, iter: T)
where T: IntoIterator, T::Item: Unsize<U>,

Extends the list with the contents of iter after unsizing them.

Source

pub fn from_iter_unsize_in<T>(iter: T, allocator: A) -> Self
where T: IntoIterator, T::Item: Unsize<U>,

Creates a DynList from the contents of iter in allocator after unsizing the elements.

Source§

impl<U> DynList<U>
where U: ?Sized,

Source

pub fn from_iter_unsize<T>(iter: T) -> Self
where T: IntoIterator, T::Item: Unsize<U>,

Creates a DynList from the contents of iter after unsizing the elements.

Source§

impl<T, A> DynList<T, A>
where A: Allocator,

Source

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.

Source

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.

Source

pub fn allocate_uninit_sized_front(&mut self) -> MaybeUninitNode<'_, T, A>

Allocates an uninitialised, sized node at the front of the list.

Source

pub fn allocate_uninit_sized_back(&mut self) -> MaybeUninitNode<'_, T, A>

Allocates an uninitialised, sized node at the back of the list.

Source

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.

Source

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.

Source

pub fn push_front(&mut self, value: T)

Pushes value to the front of the list.

Source

pub fn push_back(&mut self, value: T)

Pushes value to the back of the list.

Examples found in repository?
examples/test.rs (line 6)
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

pub fn pop_front(&mut self) -> Option<T>

Removes the front value from the list and returns it.

Source

pub fn pop_back(&mut self) -> Option<T>

Removes the back value from the list and returns it.

Source

pub const fn into_iter(self) -> IntoIter<T, A>

Converts the list to an iterator that yields the elements.

Source§

impl<T, A> DynList<[T], A>
where A: Allocator,

Source

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.

Source

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.

Source

pub fn allocate_uninit_slice_front( &mut self, length: usize, ) -> MaybeUninitNode<'_, [T], A>

Allocates an uninitialised slice node at the front of the list.

Source

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?
examples/slice.rs (line 10)
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 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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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,

Source

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.

Source

pub fn into_bytes(self) -> DynList<[u8], A>

Converts the list of string slices to a list of byte slices.

Source

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.

Source

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.

Source

pub fn allocate_uninit_str_front( &mut self, length: usize, ) -> MaybeUninitNode<'_, str, A>

Allocates an uninitialised str node at the front of the list.

Source

pub fn allocate_uninit_str_back( &mut self, length: usize, ) -> MaybeUninitNode<'_, str, A>

Allocates an uninitialised str node at the back of the list.

Source

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.

Source

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.

Source

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

Copies the string slice src and pushes it to the front of the list.

Source

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

Copies the string slice src and pushes it to the back of the list.

Examples found in repository?
examples/str.rs (line 7)
4
5
6
7
8
9
10
11
fn main() {
    let mut list = DynList::<str>::new();

    list.push_back_copy_str("Hello,");
    list.push_back_copy_str(" World!");

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

impl<U, A> DynList<U, A>
where U: ?Sized, A: Allocator,

Source

pub const fn new_in(allocator: A) -> Self

Creates an empty DynList in the given allocator.

Source

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.

Source

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 ends are not None, they must have come from a call to Self::into_raw_parts with a U with the same layout and invariants.
  • allocator must be valid for the nodes in the list.
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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!");
Source

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?
examples/debug.rs (line 9)
6
7
8
9
10
11
12
13
14
fn main() {
    let mut list = DynList::<dyn Debug>::new();

    list.push_back_unsize("Hello, World");
    list.push_back_unsize(0);
    list.push_back_unsize([1, 2, 3, 4]);

    println!("{list:?}");
}
More examples
Hide additional examples
examples/slice.rs (line 7)
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 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!

Source

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!

Source

pub fn delete_front(&mut self) -> bool

Deletes and drops the node at the front of the list.

Returns true if a node was removed and false if the list was empty.

§Examples
let mut list = DynList::<dyn Debug>::new();
assert!(!list.delete_front());

list.push_back_unsize("Hello, World!");
assert!(list.delete_front());
Source

pub fn delete_back(&mut self) -> bool

Deletes and drops the node at the back of the list.

Returns true if a node was removed and false if the list was empty.

§Examples
let mut list = DynList::<dyn Debug>::new();
assert!(!list.delete_back());

list.push_back_unsize("Hello, World!");
assert!(list.delete_back());
Source

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.

Source

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.

Source

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);
Source

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);
Source

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.

Source

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.

Source

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?
examples/test.rs (line 10)
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

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.

Source

pub const fn iter(&self) -> Iter<'_, U>

Creates an iterator over references to the items in the list.

Source

pub const fn iter_mut(&mut self) -> IterMut<'_, U>

Creates an iterator over mutable references to the items in the list.

Source

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.

Source

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.

Source

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,

Source

pub const fn new() -> Self

Creates an empty DynList.

Examples found in repository?
examples/str.rs (line 5)
4
5
6
7
8
9
10
11
fn main() {
    let mut list = DynList::<str>::new();

    list.push_back_copy_str("Hello,");
    list.push_back_copy_str(" World!");

    println!("{list:?}");
}
More examples
Hide additional examples
examples/debug.rs (line 7)
6
7
8
9
10
11
12
13
14
fn main() {
    let mut list = DynList::<dyn Debug>::new();

    list.push_back_unsize("Hello, World");
    list.push_back_unsize(0);
    list.push_back_unsize([1, 2, 3, 4]);

    println!("{list:?}");
}
examples/test.rs (line 4)
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:?}");
}
examples/slice.rs (line 5)
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<U, A> Clone for DynList<U, A>
where U: ?Sized + CloneToUninit, A: Allocator + Clone,

Source§

fn clone(&self) -> Self

Returns a copy 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<U, A> Debug for DynList<U, A>
where U: ?Sized + Debug, A: Allocator,

Source§

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

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

impl<U> Default for DynList<U>
where U: ?Sized,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<U, A> Drop for DynList<U, A>
where U: ?Sized, A: Allocator,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, Item, A> Extend<&'a Item> for DynList<Item, A>
where Item: Copy, A: Allocator,

Source§

fn extend<T: IntoIterator<Item = &'a Item>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<Item, A> Extend<Item> for DynList<Item, A>
where A: Allocator,

Source§

fn extend<T: IntoIterator<Item = Item>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<Item> FromIterator<Item> for DynList<Item>

Source§

fn from_iter<T: IntoIterator<Item = Item>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, U: ?Sized, A> IntoIterator for &'a DynList<U, A>
where A: Allocator,

Source§

type Item = &'a U

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, U>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, U: ?Sized, A> IntoIterator for &'a mut DynList<U, A>
where A: Allocator,

Source§

type Item = &'a mut U

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, U>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, A> IntoIterator for DynList<T, A>
where A: Allocator,

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, A>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<U, A> Send for DynList<U, A>
where U: ?Sized + Send, A: Allocator + Send,

Source§

impl<U, A> Sync for DynList<U, A>
where U: ?Sized + Sync, A: Allocator + Sync,

Auto Trait Implementations§

§

impl<U, A> Freeze for DynList<U, A>
where A: Freeze, U: ?Sized,

§

impl<U, A> RefUnwindSafe for DynList<U, A>

§

impl<U, A> Unpin for DynList<U, A>
where A: Unpin, U: Unpin + ?Sized,

§

impl<U, A> UnwindSafe for DynList<U, A>
where A: UnwindSafe, U: UnwindSafe + ?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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.