//! # Node type //! //! Provides a type that holds data and a pointer to the next structure. use core::fmt; use core::fmt::{Debug, Formatter}; /// # Node /// /// Encapsulates a data element and a pointer to the next `Queue` item #[derive(Copy, Clone)] pub struct Node<'a, T: Sized> { /// # Data /// /// The encapsulated data pub data: T, /// # Pointer to the next item pub next: Option<*mut Node<'a, T>>, } impl Node<'_, T> { /// # Constructor pub const fn new(data: T) -> Self { Self { data, next: None } } /// # Get the inner data /// /// Returns a borrow of the underlying data. pub fn inner(&mut self) -> &mut T { &mut self.data } /// # Get pointer to inner data pub fn ptr(&mut self) -> *mut u8 { self.inner() as *mut T as *mut u8 } } /// # Sharing Thread Safety for Node unsafe impl Send for Node<'_, T> {} impl Debug for Node<'_, T> { /// # Debug formatter for `Node` /// /// Output the encapsulated data fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { return write!(f, "{:?}", self.data); } }