Skip to main content Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. Rust
  4. pw_kernel
  5. list
  6. RandomAccessForeignList

RandomAccessForeignList

Struct RandomAccessForeignList 

Source
pub struct RandomAccessForeignList<T, A: Adapter<T>> { /* private fields */ }
Expand description

A variant of ForeignList that allows safely removal of arbitrary nodes in exchange no pop operations.

When a node is added to a RandomAccessForeignList, a RandomAccessKey is returned. The node may only be removed from this list by passing that key to RandomAccessForeignList::remove_element().

§Example

use core::ptr::NonNull;

use foreign_box::ForeignBox;
use list::{Link, RandomAccessForeignList, define_adapter};

struct Element {
    value: u32,
    link: Link,
}

define_adapter!(Adapter => Element::link);

let mut element1 = Element {
    value: 1,
    link: Link::new(),
};
let mut element2 = Element {
    value: 2,
    link: Link::new(),
};
let mut element3 = Element {
    value: 3,
    link: Link::new(),
};

let mut list = RandomAccessForeignList::<Element, Adapter>::new();
let key3 = list.push_front(unsafe { ForeignBox::new_from_ptr(&raw mut element3) });
let key2 = list.push_front(unsafe { ForeignBox::new_from_ptr(&raw mut element2) });
let key1 = list.push_front(unsafe { ForeignBox::new_from_ptr(&raw mut element1) });

let removed_element = list.remove_element(key2);
assert_eq!(removed_element.consume(), NonNull::new(&raw mut element2).unwrap());

let _ = list.remove_element(key1).consume();
let _ = list.remove_element(key3).consume();

Implementations§

Source§

impl<T, A: Adapter<T>> RandomAccessForeignList<T, A>

Source

pub const fn new() -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn push_front(&mut self, element: ForeignBox<T>) -> RandomAccessKey<T, A>

Source

pub fn push_back(&mut self, element: ForeignBox<T>) -> RandomAccessKey<T, A>

Source

pub fn for_each<E, F: FnMut(&T) -> Result<(), E>>( &self, callback: F, ) -> Result<(), E>

Source

pub fn iter(&self) -> Iter<'_, T, A>

Source

pub fn remove_element(&mut self, key: RandomAccessKey<T, A>) -> ForeignBox<T>

Auto Trait Implementations§

§

impl<T, A> !RefUnwindSafe for RandomAccessForeignList<T, A>

§

impl<T, A> !UnwindSafe for RandomAccessForeignList<T, A>

§

impl<T, A> Forget for RandomAccessForeignList<T, A>

§

impl<T, A> Freeze for RandomAccessForeignList<T, A>
where ForeignList<T, A>: Freeze,

§

impl<T, A> Move for RandomAccessForeignList<T, A>

§

impl<T, A> Send for RandomAccessForeignList<T, A>
where ForeignList<T, A>: Send,

§

impl<T, A> Sync for RandomAccessForeignList<T, A>
where ForeignList<T, A>: Sync,

§

impl<T, A> Unpin for RandomAccessForeignList<T, A>
where ForeignList<T, A>: Unpin,

§

impl<T, A> UnsafeUnpin for RandomAccessForeignList<T, A>
where ForeignList<T, A>: UnsafeUnpin,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = !

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.