diff --git a/src/rstd/collections.rs b/src/rstd/collections.rs index 3db9aad..926addf 100644 --- a/src/rstd/collections.rs +++ b/src/rstd/collections.rs @@ -3,3 +3,4 @@ pub mod avl; pub mod pair; pub mod stack; +pub mod tree; diff --git a/src/rstd/collections/tree.rs b/src/rstd/collections/tree.rs new file mode 100644 index 0000000..10ff42d --- /dev/null +++ b/src/rstd/collections/tree.rs @@ -0,0 +1,40 @@ +use std::{error::Error, fmt::Display}; + +use crate::rstd::{atomic::au64::*, point::*}; + +#[derive(Debug)] +pub enum TreeParseError { + Int(IntParseError), + Point(PointParseError), + Key(E), +} + +impl From for TreeParseError { + fn from(value: IntParseError) -> Self { + Self::Int(value) + } +} + +impl From for TreeParseError { + fn from(value: PointParseError) -> Self { + Self::Point(value) + } +} + +impl Display for TreeParseError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Int(int_error) => { + write!(f, "failed to parse AVL tree height: {int_error}") + } + Self::Point(point_error) => { + write!(f, "failed to parse AVL node reference: {point_error}") + } + Self::Key(key_error) => { + write!(f, "failed to parse AVL node key: {key_error}") + } + } + } +} + +impl Error for TreeParseError {}