use crate::util::NonNull;
use std::fmt;
pub(crate) struct ListEntry<Type>
where
Type: ?Sized,
{
pub(super) pred: Option<NonNull<Type>>,
pub(super) succ: Option<NonNull<Type>>,
pub(super) linked: bool,
}
impl<Type> Default for ListEntry<Type>
where
Type: ?Sized,
{
fn default() -> Self {
ListEntry {
pred: None,
succ: None,
linked: false,
}
}
}
impl<Type> PartialEq for ListEntry<Type>
where
Type: ?Sized,
{
fn eq(&self, _: &Self) -> bool {
true
}
}
impl<Type> Clone for ListEntry<Type>
where
Type: ?Sized,
{
fn clone(&self) -> Self {
Self::default()
}
}
impl<Type> Drop for ListEntry<Type>
where
Type: ?Sized,
{
fn drop(&mut self) {
assert!(!self.linked, "dropping a linked ListEntry is bad");
assert!(
self.pred.is_none() && self.succ.is_none(),
"unlinked ListEntry should not have predecessor or successor"
);
}
}
unsafe impl<Type> Send for ListEntry<Type> where Type: Send + ?Sized {}
impl<Type> fmt::Debug for ListEntry<Type>
where
Type: ?Sized,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
if self.linked {
f.write_str("linked")
} else {
f.write_str("unlinked")
}
}
}