板條箱sha2
包含類型Sha256
,其實現板條箱digest
中定義的特徵Digest
。該特徵也從sha2
轉出。使用實現來自不同板條箱的特徵的結構體
我想寫沒有提及sha2
文件,只需digest
:
merkle_tree.rs:
use digest::Digest;
#[derive(Default)]
pub struct MerkleTree<T: Digest> {
digest: T,
}
impl<T: Digest+Default> MerkleTree<T> {
pub fn new() -> MerkleTree<T> {
MerkleTree{ ..Default::default() }
}
}
main.rs:
extern crate digest;
extern crate sha2;
mod merkle_tree;
use sha2::{Digest, Sha256};
use merkle_tree::MerkleTree;
fn main() {
let mut mt = MerkleTree::<Sha256>::new();
println!("Hello, world!");
}
我有以下輸出:
error: no associated item named
new
found for typemerkle_tree::MerkleTree<sha2::Sha256>
in the current scope the traitdigest::Digest
is not implemented forsha2::Sha256
Cargo.toml:
[package]
name = "merkle_tree"
version = "0.1.0"
authors = ["Simon Prykhodko <[email protected]>"]
[dependencies]
digest = "0.4.0"
sha2 = "0.3.0"
這裏有什麼錯?
@ababo你爲什麼使用'sha2 =「0.3.0」'?最新版本是「0.4.2」。 – kennytm