1#[cfg(not(feature = "std"))]
4use core::fmt;
5
6#[cfg(feature = "std")]
7use std::{error, fmt};
8
9#[non_exhaustive]
10#[derive(Debug, Clone, Copy)]
11pub enum NodeError {
13 AppendSelf,
15 PrependSelf,
17 InsertBeforeSelf,
19 InsertAfterSelf,
21 Removed,
23 AppendAncestor,
25 PrependAncestor,
27}
28
29impl NodeError {
30 fn as_str(self) -> &'static str {
31 match self {
32 NodeError::AppendSelf => "Can not append a node to itself",
33 NodeError::PrependSelf => "Can not prepend a node to itself",
34 NodeError::InsertBeforeSelf => "Can not insert a node before itself",
35 NodeError::InsertAfterSelf => "Can not insert a node after itself",
36 NodeError::Removed => "Removed node cannot have any parent, siblings, and children",
37 NodeError::AppendAncestor => "Can not append a node to its descendant",
38 NodeError::PrependAncestor => "Can not prepend a node to its descendant",
39 }
40 }
41}
42
43impl fmt::Display for NodeError {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 f.write_str(self.as_str())
46 }
47}
48
49#[cfg(feature = "std")]
50impl error::Error for NodeError {}
51
52#[derive(Debug, Clone, Copy)]
56pub(crate) enum ConsistencyError {
57 ParentChildLoop,
59 SiblingsLoop,
61}
62
63impl fmt::Display for ConsistencyError {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 match self {
66 ConsistencyError::ParentChildLoop => f.write_str("Specified a node as its parent"),
67 ConsistencyError::SiblingsLoop => f.write_str("Specified a node as its sibling"),
68 }
69 }
70}
71
72#[cfg(feature = "std")]
73impl error::Error for ConsistencyError {}