use std::error::Error;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum NestedSetError {
NodeNotFound {
model: &'static str,
key: String,
},
MoveIntoOwnSubtree {
model: &'static str,
key: String,
target: String,
},
ScopeMismatch {
model: &'static str,
key: String,
target: String,
},
}
impl fmt::Display for NestedSetError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NodeNotFound { model, key } => {
write!(f, "The `{model}` node with the key `{key}` no longer exists.")
}
Self::MoveIntoOwnSubtree { model, key, target } => write!(
f,
"The `{model}` node `{key}` can't move next to `{target}`, which is the node itself or below it."
),
Self::ScopeMismatch { model, key, target } => write!(
f,
"The `{model}` node `{key}` can't move next to `{target}`, which is in another tree."
),
}
}
}
impl Error for NestedSetError {}