1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! 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,
},
/// 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::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 {}