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>
impl<'list, R: ScopedRawMutex, T> Node<'list, R, T>
Sourcepub fn attach<'node>(
self: Pin<&'node mut Self>,
) -> NodeHandle<'list, 'node, R, T>
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.
impl<R: ScopedRawMutex, T> Drop for Node<'_, R, T>
Drop the node, unlinking it from the list in the process.
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>
impl<'list, R, T> Sync for Node<'list, R, T>
impl<'list, R, T> Unpin for Node<'list, R, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more