#![cfg_attr(not(test), no_std)]
#![doc = include_str!("../README.md")]
mod linked_list;
mod raw_list;
pub use linked_list::List;
pub use raw_list::{GetLinks, Links, RawList};
#[macro_export(local_inner_macros)]
#[doc(hidden)]
macro_rules! __def_node_internal {
($(#[$meta:meta])* $vis:vis struct $name:ident($type:ty);) => {
$(#[$meta])*
$vis struct $name {
inner: $type,
links: $crate::Links<Self>,
}
impl $crate::GetLinks for $name {
type EntryType = Self;
#[inline]
fn get_links(t: &Self) -> &$crate::Links<Self> {
&t.links
}
}
impl $name {
#[doc = "Create a node"]
pub const fn new(inner: $type) -> Self {
Self {
inner,
links: $crate::Links::new(),
}
}
#[inline]
#[doc = "Return the referece of wrapped inner"]
pub const fn inner(&self) -> &$type {
&self.inner
}
#[inline]
#[doc = "Consumes the `node`, returning the wrapped inner"]
pub fn into_inner(self) -> $type {
self.inner
}
}
impl core::ops::Deref for $name {
type Target = $type;
#[inline]
fn deref(&self) -> &Self::Target {
&self.inner
}
}
};
($(#[$meta:meta])* $vis:vis struct $name:ident<$gen:ident>($type:ty);) => {
$(#[$meta])*
$vis struct $name<$gen> {
inner: $type,
links: $crate::Links<Self>,
}
impl<$gen> $crate::GetLinks for $name<$gen> {
type EntryType = Self;
#[inline]
fn get_links(t: &Self) -> &$crate::Links<Self> {
&t.links
}
}
impl<$gen> $name<$gen> {
#[doc = "Create a node"]
pub const fn new(inner: $type) -> Self {
Self {
inner,
links: $crate::Links::new(),
}
}
#[inline]
#[doc = "Return the referece of wrapped inner"]
pub const fn inner(&self) -> &$type {
&self.inner
}
#[inline]
#[doc = "Consumes the `node`, returning the wrapped inner"]
pub fn into_inner(self) -> $type {
self.inner
}
}
impl<$gen> core::ops::Deref for $name<$gen> {
type Target = $type;
#[inline]
fn deref(&self) -> &Self::Target {
&self.inner
}
}
};
}
#[macro_export(local_inner_macros)]
macro_rules! def_node {
($(#[$meta:meta])* $vis:vis struct $name:ident($type:ty); $($t:tt)*) => {
__def_node_internal!($(#[$meta])* $vis struct $name($type););
def_node!($($t)*);
};
($(#[$meta:meta])* $vis:vis struct $name:ident<$gen:ident>($type:ty); $($t:tt)*) => {
__def_node_internal!($(#[$meta])* $vis struct $name<$gen>($type););
def_node!($($t)*);
};
() => ()
}