use std::fmt;
use crate::path::TagPathError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
InvalidPath(TagPathError),
PathNotFound(String),
CannotMoveRoot,
CannotMoveIntoDescendant { from: String, to: String },
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidPath(error) => error.fmt(f),
Self::PathNotFound(path) => write!(f, "path not found: {path}"),
Self::CannotMoveRoot => write!(f, "cannot move the root path"),
Self::CannotMoveIntoDescendant { from, to } => {
write!(f, "cannot move {from} into its descendant {to}")
}
}
}
}
impl std::error::Error for Error {}
impl From<TagPathError> for Error {
fn from(error: TagPathError) -> Self {
Self::InvalidPath(error)
}
}
pub type Result<T> = std::result::Result<T, Error>;