1pub mod database;
10pub mod hasher;
11pub mod tree;
12
13use std::fmt::{Debug, Display};
14
15pub use database::*;
16pub use hasher::*;
17pub use tree::MerkleTree;
18
19pub type DBKey = [u8; 8];
21
22pub type Value = Vec<u8>;
24
25#[derive(Debug)]
27pub enum TreeErrorKind {
28 MerkleTreeIsFull,
29 InvalidKey,
30 IndexOutOfBounds,
31 CustomError(String),
32}
33
34#[derive(Debug)]
36pub enum DatabaseErrorKind {
37 CannotLoadDatabase,
38 DatabaseExists,
39 CustomError(String),
40}
41
42#[derive(Debug)]
44pub enum PmtreeErrorKind {
45 DatabaseError(DatabaseErrorKind),
47 TreeError(TreeErrorKind),
49 CustomError(String),
51}
52
53impl Display for PmtreeErrorKind {
54 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
55 match self {
56 PmtreeErrorKind::DatabaseError(e) => write!(f, "Database error: {e:?}"),
57 PmtreeErrorKind::TreeError(e) => write!(f, "Tree error: {e:?}"),
58 PmtreeErrorKind::CustomError(e) => write!(f, "Custom error: {e:?}"),
59 }
60 }
61}
62
63impl std::error::Error for PmtreeErrorKind {}
64
65pub type PmtreeResult<T> = std::result::Result<T, PmtreeErrorKind>;