Skip to content

Commit

Permalink
Merge pull request #29 from yejiayu/remove_debug
Browse files Browse the repository at this point in the history
refactor: Implement debug trait
  • Loading branch information
yejiayu authored Mar 26, 2019
2 parents 290036e + c803751 commit 557db48
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ The implementation is strongly inspired by [go-ethereum trie](https://github.com

```rust
/// NOTE: `Clone` must be ensured to be thread-safe.
pub trait DB: Send + Sync + Debug + Clone {
type Error: Error;
pub trait DB: Send + Sync + Clone {
type Error: ::std::error::Error;

fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>;
fn insert(&mut self, key: &[u8], value: &[u8]) -> Result<(), Self::Error>;
Expand All @@ -33,7 +33,7 @@ pub trait DB: Send + Sync + Debug + Clone {
### Decoder

```rust
pub trait NodeCodec: Sized + Debug {
pub trait NodeCodec: Sized {
type Error: ::std::error::Error;

const HASH_LENGTH: usize;
Expand Down
3 changes: 1 addition & 2 deletions src/codec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::fmt::Debug;
use std::hash;

use crate::errors::RLPCodecError;
Expand All @@ -13,7 +12,7 @@ pub enum DataType<'a> {
Hash(&'a [u8]),
}

pub trait NodeCodec: Sized + Debug {
pub trait NodeCodec: Sized {
type Error: ::std::error::Error;

const HASH_LENGTH: usize;
Expand Down
3 changes: 1 addition & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::collections::HashMap;
use std::error::Error;
use std::fmt::Debug;
use std::sync::{Arc, RwLock};

use crate::errors::MemDBError;

/// NOTE: `Clone` must be ensured to be thread-safe.
pub trait DB: Send + Sync + Debug + Clone {
pub trait DB: Send + Sync + Clone {
type Error: Error;

fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>;
Expand Down
29 changes: 9 additions & 20 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::fmt;
use crate::codec::NodeCodec;
use crate::db::DB;

#[derive(Debug)]
pub enum TrieError<C: NodeCodec, D: DB> {
NodeCodec(C::Error),
DB(D::Error),
Expand Down Expand Up @@ -40,25 +39,15 @@ where
}
}

// impl<C, D> From<C> for TrieError<C, D>
// where
// C: NodeCodec,
// D: DB,
// {
// fn from(error: C::Error) -> Self {
// TrieError::NodeCodec(error)
// }
// }
//
// impl<C, D> From<C> for TrieError<C, D>
// where
// C: NodeCodec,
// D: DB,
// {
// fn from(error: D::Error) -> Self {
// TrieError::DB(error)
// }
// }
impl<C, D> fmt::Debug for TrieError<C, D>
where
C: NodeCodec,
D: DB,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
}
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum MemDBError {}
Expand Down

0 comments on commit 557db48

Please sign in to comment.