My package has a structure like this.
src
├── block.rs
├── main.rs
└── traits
├── hashable.rs
└── mod.rs
In hashable.rs,
pub trait Hashable {
fn bytes(&self) -> Vec<u8>;
fn hash(&self) -> Vec<u8> {
crypto_hash::digest(crypto_hash::Algorithm::SHA256, &self.bytes());
}
}
I tried to use mod to import Hashable trait from block.rs like this
mod traits;
type BlockHash = Vec<u8>;
pub struct Block {
pub index: u32,
pub timestamp: u128,
pub payload: String,
pub nonce: u64,
pub hash: BlockHash,
pub prev_hash: BlockHash,
}
impl Block {
pub fn new(index: u32, timestamp: u128, payload: String, nonce: u64, prev_hash: BlockHash) -> Self {
Block {
index,
timestamp,
payload,
nonce,
hash: vec![0; 32],
prev_hash,
}
}
}
but this didn't work. I just can use this from main.rs file, so how I can use Hashable trait from block.rs file.