chore: add template for the project

This commit is contained in:
Magamedrasul Ibragimov 2022-10-19 13:42:21 +03:00
parent 5e618fb529
commit fd89299abe
1 changed files with 58 additions and 10 deletions

View File

@ -1,14 +1,62 @@
pub fn add(left: usize, right: usize) -> usize { pub struct Error(String);
left + right pub type Result<T> = std::result::Result<T, Error>;
}
#[cfg(test)] pub struct VecDB;
mod tests { pub struct Poseidon;
use super::*;
#[test] pub type DefaultDatabase = VecDB;
fn it_works() { pub type DefaultHasher = Poseidon;
let result = add(2, 2);
assert_eq!(result, 4); impl Hasher for Poseidon {
type Fr = i32;
fn hash(_input: &[i32]) -> i32 {
0
} }
} }
impl Database for VecDB {
fn new(dbpath: &str) -> Self {
Self {}
}
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
Ok(Some(vec![]))
}
fn put(&mut self, key: &[u8]) -> Result<()> {
Ok(())
}
fn delete(&mut self, key: &[u8]) -> Result<()> {
Ok(())
}
}
pub trait Hasher {
type Fr: Copy + Eq + Default;
fn hash(input: &[Self::Fr]) -> Self::Fr;
}
pub trait Database {
fn new(dbpath: &str) -> Self;
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
fn put(&mut self, key: &[u8]) -> Result<()>;
fn delete(&mut self, key: &[u8]) -> Result<()>;
}
pub struct MerkleTree<D = DefaultDatabase, H = DefaultHasher>
where
D: Database,
H: Hasher,
{
db: D,
h: H,
}
impl MerkleTree {}
impl<D, H> MerkleTree<D, H>
where
D: Database,
H: Hasher,
{
}