#[cfg(not(feature = "std"))]
use core::fmt;
#[cfg(feature = "std")]
use std::{error, fmt};
#[non_exhaustive]
#[derive(Debug, Clone, Copy)]
pub enum NodeError {
AppendSelf,
PrependSelf,
InsertBeforeSelf,
InsertAfterSelf,
Removed,
AppendAncestor,
PrependAncestor,
}
impl NodeError {
fn as_str(self) -> &'static str {
match self {
NodeError::AppendSelf => "Can not append a node to itself",
NodeError::PrependSelf => "Can not prepend a node to itself",
NodeError::InsertBeforeSelf => "Can not insert a node before itself",
NodeError::InsertAfterSelf => "Can not insert a node after itself",
NodeError::Removed => "Removed node cannot have any parent, siblings, and children",
NodeError::AppendAncestor => "Can not append a node to its descendant",
NodeError::PrependAncestor => "Can not prepend a node to its descendant",
}
}
}
impl fmt::Display for NodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(feature = "std")]
impl error::Error for NodeError {}
#[derive(Debug, Clone, Copy)]
pub(crate) enum ConsistencyError {
ParentChildLoop,
SiblingsLoop,
}
impl fmt::Display for ConsistencyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ConsistencyError::ParentChildLoop => f.write_str("Specified a node as its parent"),
ConsistencyError::SiblingsLoop => f.write_str("Specified a node as its sibling"),
}
}
}
#[cfg(feature = "std")]
impl error::Error for ConsistencyError {}