laravel-nestedset 0.2.1

Nested set trees for Laravel Rust models: fast subtree and ancestor queries, safe under concurrent writes.
Documentation
//! Nested set trees for [Laravel Rust](https://crates.io/crates/laravel-rust) models.
//!
//! A nested set stores a tree in one table: each row keeps the `lft` and `rgt` bounds of its
//! subtree, so a whole subtree or every ancestor of a node is one indexed query.
//!
//! ```no_run
//! use laravel::model::{Column, model};
//! use laravel_nestedset::NestedSet;
//!
//! #[model]
//! pub struct Category {
//!     pub id: i64,
//!     pub name: String,
//!     #[default]
//!     pub lft: i64,
//!     #[default]
//!     pub rgt: i64,
//!     pub parent_id: Option<i64>,
//! }
//!
//! impl NestedSet for Category {
//!     fn lft_column() -> Column<Self, i64> {
//!         Category::lft
//!     }
//!
//!     fn rgt_column() -> Column<Self, i64> {
//!         Category::rgt
//!     }
//!
//!     fn parent_column() -> Column<Self, Option<i64>> {
//!         Category::parent_id
//!     }
//! }
//!
//! # async fn example() -> laravel::Result<()> {
//! let mut shop = Category::create_root(Category::create().name("Shop")).await?;
//! let mut phones = shop.create_child(Category::create().name("Phones")).await?;
//! let android = phones.create_child(Category::create().name("Android")).await?;
//!
//! let subtree = shop.descendants().get().await?; // Phones, Android
//! let breadcrumbs = android.ancestors().get().await?; // Shop, Phones
//! # Ok(())
//! # }
//! ```
//!
//! The migration adds the columns with
//! [`table.nested_set()`](NestedSetBlueprint::nested_set). From there, [`NestedSet`] has:
//!
//! - creating: [`create_root`](NestedSet::create_root), [`create_child`](NestedSet::create_child),
//!   [`create_after`](NestedSet::create_after), [`create_tree`](NestedSet::create_tree) from
//!   nested [`NewNode`]s, and more;
//! - moving a subtree: [`append_to`](NestedSet::append_to),
//!   [`insert_before`](NestedSet::insert_before), [`make_root`](NestedSet::make_root),
//!   [`up`](NestedSet::up), and more;
//! - deleting a subtree: [`delete_subtree`](NestedSet::delete_subtree);
//! - queries: [`descendants`](NestedSet::descendants), [`ancestors`](NestedSet::ancestors),
//!   [`siblings`](NestedSet::siblings), [`children`](NestedSet::children), and more;
//! - conditions for any query: [`where_descendant_of`](NestedSet::where_descendant_of),
//!   [`where_ancestor_of`](NestedSet::where_ancestor_of), and more;
//! - loading by key: [`ancestors_of`](NestedSet::ancestors_of),
//!   [`subtree_of`](NestedSet::subtree_of), and more;
//! - drag-and-drop saves: [`arrange`](NestedSet::arrange) from nested [`Arrangement`]s;
//! - repairs: [`check_tree`](NestedSet::check_tree) and [`fix_tree`](NestedSet::fix_tree), also
//!   from the console through [`NestedSetServiceProvider`].
//!
//! [`LoadRelatives`] loads the ancestors or subtrees of a whole list with one query.
//!
//! [`IntoTree::into_tree`] nests a query's result into [`TreeNode`]s for JSON and templates, and
//! [`Scope`] keeps several trees in one table. Every write locks its tree, so concurrent writers
//! take turns. See the [README](https://github.com/axvilab/laravel-nestedset-rs) for the guide.

mod arrange;
mod chain;
mod check;
mod commands;
mod error;
mod event;
mod node;
mod ops;
mod relatives;
mod schema;
mod scope;
mod tree;

pub use crate::arrange::Arrangement;
pub use crate::check::TreeReport;
pub use crate::commands::NestedSetServiceProvider;
pub use crate::error::NestedSetError;
pub use crate::event::{TreeChange, TreeChanged};
pub use crate::node::NestedSet;
pub use crate::relatives::{LoadRelatives, WithAncestors, WithCount};
pub use crate::schema::NestedSetBlueprint;
pub use crate::scope::Scope;
pub use crate::tree::{IntoTree, NewNode, TreeNode};