#[cfg(not(feature = "std"))]
use core::{fmt, error::Error};
#[cfg(feature = "std")]
use std::{fmt, error::Error};
#[derive(Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum NodeError {
DowngradeNotParent,
RootDowngradeNotAllowed,
IllegalDowngradeWithChildren(usize),
ParentUpgradeNotAllowed,
ExpectedALeafNode,
ExpectedARootNode,
NotAParent,
AlreadyBorrowed,
ParentNodeNotFound,
ExpectedChildren
}
impl fmt::Display for NodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ParentUpgradeNotAllowed => write!(f, "Upgrage failure Node was not not a leaf"),
Self::DowngradeNotParent => write!(f, "Downgrade failure Node was not not a parent"),
Self::RootDowngradeNotAllowed => write!(f, "Root node cannot be downgraded"),
Self::IllegalDowngradeWithChildren(children) => write!(f, "Downgrade failure, node still has reference to {} children", children),
Self::ExpectedALeafNode => write!(f, "Expected a leaf node"),
Self::ExpectedARootNode => write!(f, "Expected a root node"),
Self::NotAParent => write!(f, "Expected a node Node::Parent"),
Self::AlreadyBorrowed => write!(f, "Node is already borrowed mutably"),
Self::ParentNodeNotFound => write!(f, "Parent not found"),
Self::ExpectedChildren => write!(f, "Expected the node to have children")
}
}
}
impl Error for NodeError {}