generational_indextree/
error.rs1#[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}
24
25impl NodeError {
26 fn as_str(self) -> &'static str {
27 match self {
28 NodeError::AppendSelf => "Can not append a node to itself",
29 NodeError::PrependSelf => "Can not prepend a node to itself",
30 NodeError::InsertBeforeSelf => "Can not insert a node before itself",
31 NodeError::InsertAfterSelf => "Can not insert a node after itself",
32 NodeError::Removed => "Removed node cannot have any parent, siblings, and children",
33 }
34 }
35}
36
37impl fmt::Display for NodeError {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 f.write_str(self.as_str())
40 }
41}
42
43#[cfg(feature = "std")]
44impl error::Error for NodeError {}
45
46#[derive(Debug, Clone, Copy)]
50pub(crate) enum ConsistencyError {
51 ParentChildLoop,
53 SiblingsLoop,
55}
56
57impl fmt::Display for ConsistencyError {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 match self {
60 ConsistencyError::ParentChildLoop => f.write_str("Specified a node as its parent"),
61 ConsistencyError::SiblingsLoop => f.write_str("Specified a node as its sibling"),
62 }
63 }
64}
65
66#[cfg(feature = "std")]
67impl error::Error for ConsistencyError {}