Struct CLinkedListConst

Source
pub struct CLinkedListConst<T, N: Fn(&T) -> *const T> { /* private fields */ }
Expand description

Wraps a C linked list comprised of const pointers between nodes.

Implementations§

Source§

impl<'a, T: 'a, N: Fn(&T) -> *const T + 'a> CLinkedListConst<T, N>

Source

pub unsafe fn from_ptr(head: *const T, next: N) -> CLinkedListConst<T, N>

Construct a CLinkedListConst by wrapping a C linked list. head points to the head element of the list or is NULL for a list of length 0. next is a function that takes a node and returns a pointer to the next element.

§Example

To wrap this C type.

struct LinkedListNode {
    int value;
    const struct LinkedListNode *next;
};

Call this function as CLinkedListConst::from_ptr(ptr_to_head, |n| n.next).

§Unsafety

This function is unsafe because it is up to the caller to ensure that head is valid.

Source

pub fn iter(&'a self) -> CLinkedListConstIter<'a, T, N>

Iterate over the linked list, returning immutable references to the nodes of the list.

Source

pub fn is_empty(&self) -> bool

Returns true if the list is empty.

Source

pub fn len(&self) -> usize

Calculates the length of the list. This is an O(n) operation.

Source

pub fn front(&self) -> Option<&T>

Provides a reference to the front element in the list, or None if the list is empty.

Trait Implementations§

Source§

impl<'a, T: Debug + 'a, N: Fn(&T) -> *const T + 'a> Debug for CLinkedListConst<T, N>

Source§

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

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

impl<'a, T: 'a, N: Fn(&T) -> *const T + 'a> IntoIterator for &'a CLinkedListConst<T, N>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = CLinkedListConstIter<'a, T, N>

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

fn into_iter(self) -> CLinkedListConstIter<'a, T, N>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, N> Freeze for CLinkedListConst<T, N>
where N: Freeze,

§

impl<T, N> RefUnwindSafe for CLinkedListConst<T, N>

§

impl<T, N> !Send for CLinkedListConst<T, N>

§

impl<T, N> !Sync for CLinkedListConst<T, N>

§

impl<T, N> Unpin for CLinkedListConst<T, N>
where N: Unpin,

§

impl<T, N> UnwindSafe for CLinkedListConst<T, N>

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.