laravel-nestedset 0.1.0

Nested set trees for Laravel Rust models: fast subtree and ancestor queries, safe under concurrent writes.
Documentation
//! The package's errors.

use std::error::Error;
use std::fmt;

/// An operation on a tree that can't be done.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum NestedSetError {
    /// The node an operation starts from is no longer in the table.
    NodeNotFound {
        /// The model's name.
        model: &'static str,
        /// The node's key.
        key: String,
    },
    /// A move would put a node inside its own subtree.
    MoveIntoOwnSubtree {
        /// The model's name.
        model: &'static str,
        /// The moved node's key.
        key: String,
        /// The key of the node it was to move next to.
        target: String,
    },
    /// A move would take a node into another tree of the table.
    ScopeMismatch {
        /// The model's name.
        model: &'static str,
        /// The moved node's key.
        key: String,
        /// The key of the node in the other tree.
        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 {}