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
66
67
68
69
70
#[cfg(not(feature = "std"))]
use core::fmt;
#[cfg(feature = "std")]
use std::{error, fmt};
#[derive(Debug, Clone, Copy)]
pub enum NodeError {
AppendSelf,
PrependSelf,
InsertBeforeSelf,
InsertAfterSelf,
Removed,
#[doc(hidden)]
__Nonexhaustive,
}
impl NodeError {
fn as_str(self) -> &'static str {
match self {
NodeError::AppendSelf => "Can not append a node to itself",
NodeError::PrependSelf => "Can not prepend a node to itself",
NodeError::InsertBeforeSelf => "Can not insert a node before itself",
NodeError::InsertAfterSelf => "Can not insert a node after itself",
NodeError::Removed => "Removed node cannot have any parent, siblings, and children",
NodeError::__Nonexhaustive => panic!("`__Nonexhaustive` should not be used"),
}
}
}
impl fmt::Display for NodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(feature = "std")]
impl error::Error for NodeError {}
#[derive(Debug, Clone, Copy)]
pub(crate) enum ConsistencyError {
ParentChildLoop,
SiblingsLoop,
}
impl fmt::Display for ConsistencyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ConsistencyError::ParentChildLoop => f.write_str("Specified a node as its parent"),
ConsistencyError::SiblingsLoop => f.write_str("Specified a node as its sibling"),
}
}
}
#[cfg(feature = "std")]
impl error::Error for ConsistencyError {}