use crate::{Node, NodeDataLazyClose, Variant};
impl<'a, V, T> Node<'a, V, T>
where
V: Variant<'a, T, Storage = NodeDataLazyClose<T>>,
{
pub fn closed_node() -> Self {
Self {
data: NodeDataLazyClose::closed(),
prev: Default::default(),
next: Default::default(),
}
}
#[inline(always)]
pub fn is_closed(&self) -> bool {
self.data.is_closed()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{MemoryReclaimOnThreshold, NodeRefNone, NodeRefSingle, NodeRefs, NodeRefsVec};
#[derive(Debug, Clone, Copy)]
struct Var;
impl<'a> Variant<'a, char> for Var {
type Storage = NodeDataLazyClose<char>;
type Prev = NodeRefSingle<'a, Self, char>;
type Next = NodeRefsVec<'a, Self, char>;
type Ends = NodeRefNone;
type MemoryReclaim = MemoryReclaimOnThreshold<2>;
}
#[test]
fn closed_node() {
let node = Node::<Var, _>::closed_node();
assert!(node.prev().get().is_none());
assert!(node.next().get().is_empty());
assert!(node.data().is_none());
}
#[test]
fn is_closed_active() {
let node = Node::<Var, _>::closed_node();
assert!(node.is_closed());
assert!(!node.is_active());
let node = Node::<Var, _>::new_free_node('x');
assert!(!node.is_closed());
assert!(node.is_active());
}
}