zk_kit_pmt/
lib.rs

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
11/// Denotes keys in a database
12pub type DBKey = [u8; 8];
13
14/// Denotes values in a database
15pub type Value = Vec<u8>;
16
17/// Denotes pmtree Merkle tree errors
18#[derive(Debug)]
19pub enum TreeErrorKind {
20    MerkleTreeIsFull,
21    InvalidKey,
22    IndexOutOfBounds,
23    CustomError(String),
24}
25
26/// Denotes pmtree database errors
27#[derive(Debug)]
28pub enum DatabaseErrorKind {
29    CannotLoadDatabase,
30    DatabaseExists,
31    CustomError(String),
32}
33
34/// Denotes pmtree errors
35#[derive(Debug)]
36pub enum PmtreeErrorKind {
37    /// Error in database
38    DatabaseError(DatabaseErrorKind),
39    /// Error in tree
40    TreeError(TreeErrorKind),
41    /// Custom error
42    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
57/// Custom `Result` type with custom `Error` type
58pub type PmtreeResult<T> = std::result::Result<T, PmtreeErrorKind>;