1pub mod database;
2pub mod hasher;
3pub mod tree;
4
5use std::fmt::{Debug, Display};
6
7pub use database::*;
8pub use hasher::*;
9pub use tree::MerkleTree;
10
11pub type DBKey = [u8; 8];
13
14pub type Value = Vec<u8>;
16
17#[derive(Debug)]
19pub enum TreeErrorKind {
20 MerkleTreeIsFull,
21 InvalidKey,
22 IndexOutOfBounds,
23 CustomError(String),
24}
25
26#[derive(Debug)]
28pub enum DatabaseErrorKind {
29 CannotLoadDatabase,
30 DatabaseExists,
31 CustomError(String),
32}
33
34#[derive(Debug)]
36pub enum PmtreeErrorKind {
37 DatabaseError(DatabaseErrorKind),
39 TreeError(TreeErrorKind),
41 CustomError(String),
43}
44
45impl Display for PmtreeErrorKind {
46 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
47 match self {
48 PmtreeErrorKind::DatabaseError(e) => write!(f, "Database error: {e:?}"),
49 PmtreeErrorKind::TreeError(e) => write!(f, "Tree error: {e:?}"),
50 PmtreeErrorKind::CustomError(e) => write!(f, "Custom error: {e:?}"),
51 }
52 }
53}
54
55impl std::error::Error for PmtreeErrorKind {}
56
57pub type PmtreeResult<T> = std::result::Result<T, PmtreeErrorKind>;