laravel-nestedset 0.2.2

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 node made by `create_root_in` isn't in the scope it was given: the scope doesn't name
    /// the model's scope columns.
    OutsideScope {
        /// The model's name.
        model: &'static str,
    },
    /// An arrangement lists the same node twice.
    DuplicateKey {
        /// The model's name.
        model: &'static str,
        /// The node's key.
        key: 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::OutsideScope { model } => write!(
                f,
                "The new `{model}` root isn't in the scope it was created in: build the scope from the same columns as `{model}::scope`."
            ),
            Self::DuplicateKey { model, key } => {
                write!(f, "The arrangement lists the `{model}` node `{key}` more than once.")
            }
            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 {}