Skip to main content

Node

Struct Node 

Source
pub struct Node<'list, R: ScopedRawMutex, T> { /* private fields */ }
Expand description

A Node that can be added to a PinList.

Can be attached to a PinList by calling Node::attach() after pinning, which will return a NodeHandle.

Pinning the node is essential to ensure that the destructor cannot be skipped, as the node is unlinked when Drop is called, taking the mutex for a short time to remove the node.

§Example

use core::pin::pin;
use pinlist::blocking::{PinList, Node};
use mutex::raw_impls::cs::CriticalSectionRawMutex as CsRm;

// Our LIST contains all attached nodes
static LIST: PinList<CsRm, u64> = PinList::new();

// Create the node for the list
let node_a = Node::new_for(&LIST, 123);
let node_a = pin!(node_a);
let hdl_a = node_a.attach();

// Access through the handle
assert_eq!(123, hdl_a.with_lock(|n| *n));
// Access through the list
LIST.with_iter(|mut i| assert_eq!(123, *i.next().unwrap()))

Implementations§

Source§

impl<'list, R: ScopedRawMutex, T> Node<'list, R, T>

Source

pub const fn new_for(list: &'list PinList<R, T>, t: T) -> Self

Create a new Node for the given PinList.

Source

pub fn attach<'node>( self: Pin<&'node mut Self>, ) -> NodeHandle<'list, 'node, R, T>

Attach the given node to the list it was created with.

This will return a NodeHandle. The item will remain in the list until the Node is dropped.

The mutex will be locked briefly to insert the node in the list.

Trait Implementations§

Source§

impl<R: ScopedRawMutex, T> Drop for Node<'_, R, T>

Drop the node, unlinking it from the list in the process.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'list, R, T> !Freeze for Node<'list, R, T>

§

impl<'list, R, T> !RefUnwindSafe for Node<'list, R, T>

§

impl<'list, R, T> !UnsafeUnpin for Node<'list, R, T>

§

impl<'list, R, T> !UnwindSafe for Node<'list, R, T>

§

impl<'list, R, T> Send for Node<'list, R, T>
where NodeHeader<T>: Send, &'list PinList<R, T>: Send,

§

impl<'list, R, T> Sync for Node<'list, R, T>
where NodeHeader<T>: Sync, &'list PinList<R, T>: Sync,

§

impl<'list, R, T> Unpin for Node<'list, R, T>
where NodeHeader<T>: Unpin, &'list PinList<R, T>: Unpin,

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 = !

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

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

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.