rstd::colections::tree

This commit is contained in:
AF 2023-06-18 12:28:58 +00:00
parent d49c8a7133
commit be6924fe4c
2 changed files with 41 additions and 0 deletions

View File

@ -3,3 +3,4 @@
pub mod avl; pub mod avl;
pub mod pair; pub mod pair;
pub mod stack; pub mod stack;
pub mod tree;

View File

@ -0,0 +1,40 @@
use std::{error::Error, fmt::Display};
use crate::rstd::{atomic::au64::*, point::*};
#[derive(Debug)]
pub enum TreeParseError<E> {
Int(IntParseError),
Point(PointParseError),
Key(E),
}
impl<E> From<IntParseError> for TreeParseError<E> {
fn from(value: IntParseError) -> Self {
Self::Int(value)
}
}
impl<E> From<PointParseError> for TreeParseError<E> {
fn from(value: PointParseError) -> Self {
Self::Point(value)
}
}
impl<E: Display> Display for TreeParseError<E> {
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<E: Error> Error for TreeParseError<E> {}