Reputation: 303
I am trying to call a method from a rust crate and getting an error stating that a trait is not implemented for one of the methods I am passing however when I look the method up on docs.rs it does appear to be implementing the required trait.
I am trying to call a method called new_with_count
from a crate called wagyu_ethereum.
The code I am using to make the call is here:
use rand::{rngs::StdRng, SeedableRng};
use wagyu_ethereum::*;
use wagyu_model::mnemonic::MnemonicCount;
use wagyu_model::MnemonicError;
pub fn generate_mnemonic() -> Result<String, MnemonicError> {
let mut rng = StdRng::from_entropy();
let mnemonic = EthereumMnemonic::<
wagyu_ethereum::network::Mainnet,
wagyu_ethereum::wordlist::English,
>::new_with_count(&mut rng, 24)?;
Ok(String::from("placeholder"))
}
The code for the method (from the projects GitHub page:
impl<N: EthereumNetwork, W: EthereumWordlist> MnemonicCount for EthereumMnemonic<N, W> {
/// Returns a new mnemonic given the word count.
fn new_with_count<R: Rng>(rng: &mut R, word_count: u8) -> Result<Self, MnemonicError> {
let length: usize = match word_count {
12 => 16,
15 => 20,
18 => 24,
21 => 28,
24 => 32,
wc => return Err(MnemonicError::InvalidWordCount(wc)),
};
let entropy: [u8; 32] = rng.gen();
Ok(Self {
entropy: entropy[0..length].to_vec(),
_network: PhantomData,
_wordlist: PhantomData,
})
}
}
The error:
error[E0277]: the trait bound `StdRng: rand_core::RngCore` is not satisfied
--> src/lib.rs:12:23
|
9 | let mnemonic = EthereumMnemonic::<
| ____________________-
10 | | wagyu_ethereum::network::Mainnet,
11 | | wagyu_ethereum::wordlist::English,
12 | | >::new_with_count(&mut rng, 24)?;
| | - ^^^^^^^^ the trait `rand_core::RngCore` is not implemented for `StdRng`
| |_____________________|
| required by a bound introduced by this call
|
= help: the following other types implement trait `rand_core::RngCore`:
&'a mut R
Box<R>
rand::rngs::adapter::read::ReadRng<R>
rand::rngs::adapter::reseeding::ReseedingRng<R, Rsdr>
rand::rngs::entropy::EntropyRng
rand::rngs::mock::StepRng
rand::rngs::std::StdRng
rand::rngs::thread::ThreadRng
and 6 others
= note: required because of the requirements on the impl of `rand::Rng` for `StdRng`
note: required by a bound in `new_with_count`
--> /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/wagyu-model-0.6.3/src/mnemonic.rs:44:26
|
44 | fn new_with_count<R: Rng>(rng: &mut R, word_count: u8) -> Result<Self, MnemonicError>;
| ^^^ required by this bound in `new_with_count`
So as far as I can tell from the documentation on docs.rs it appears that StdRng
does actually implement RngCore
. I've also found this question that indicates I might be borrowing to many time but I'm not sure if it is relevant here because I don't think I am borrowing as many times.
Finally on the projects Github account they have instances of calling the method the same way I am doing (method call, rng assignment). This is what prompted me to use this method. Their program also works when you run it. So the question I have is what am I doing wrong when trying to call this method?
Upvotes: 0
Views: 1080
Reputation: 22676
At the time of writing, the newest versions are:
rand = "0.8.5"
wagyu-ethereum = "0.6.3"
wagyu-model = "0.6.3"
It seems that a version mismatch exists here. wagyu-ethereum = "0.6.3"
depends on rand = "0.7.3"
, while the current default if you do cargo add rand
is rand = "0.8.5"
.
You can see this in cargo tree
:
rust_test v0.1.0 (/home/me/work/rust_test)
├── rand v0.8.5
│ ├── libc v0.2.139
│ ├── rand_chacha v0.3.1
│ │ ├── ppv-lite86 v0.2.17
│ │ └── rand_core v0.6.4
│ │ └── getrandom v0.2.8
│ │ ├── cfg-if v1.0.0
│ │ └── libc v0.2.139
│ └── rand_core v0.6.4 (*)
├── wagyu-ethereum v0.6.3
│ ├── base58 v0.1.0
│ ├── bitvec v0.17.4
│ │ ├── either v1.8.0
│ │ └── radium v0.3.0
│ ├── ethereum-types v0.9.2
│ │ ├── ethbloom v0.9.2
│ │ │ ├── crunchy v0.2.2
│ │ │ ├── fixed-hash v0.6.1
│ │ │ │ ├── byteorder v1.4.3
│ │ │ │ ├── rand v0.7.3
│ │ │ │ │ ├── getrandom v0.1.16
│ │ │ │ │ │ ├── cfg-if v1.0.0
│ │ │ │ │ │ └── libc v0.2.139
│ │ │ │ │ ├── libc v0.2.139
│ │ │ │ │ ├── rand_chacha v0.2.2
│ │ │ │ │ │ ├── ppv-lite86 v0.2.17
│ │ │ │ │ │ └── rand_core v0.5.1
│ │ │ │ │ │ └── getrandom v0.1.16 (*)
│ │ │ │ │ └── rand_core v0.5.1 (*)
│ │ │ │ ├── rustc-hex v2.1.0
│ │ │ │ └── static_assertions v1.1.0
│ │ │ ├── impl-rlp v0.2.1
│ │ │ │ └── rlp v0.4.6
│ │ │ │ └── rustc-hex v2.1.0
│ │ │ ├── impl-serde v0.3.2
│ │ │ │ └── serde v1.0.152
│ │ │ │ └── serde_derive v1.0.152 (proc-macro)
│ │ │ │ ├── proc-macro2 v1.0.49
│ │ │ │ │ └── unicode-ident v1.0.6
│ │ │ │ ├── quote v1.0.23
│ │ │ │ │ └── proc-macro2 v1.0.49 (*)
│ │ │ │ └── syn v1.0.107
│ │ │ │ ├── proc-macro2 v1.0.49 (*)
│ │ │ │ ├── quote v1.0.23 (*)
│ │ │ │ └── unicode-ident v1.0.6
│ │ │ └── tiny-keccak v2.0.2
│ │ │ └── crunchy v0.2.2
│ │ ├── fixed-hash v0.6.1 (*)
│ │ ├── impl-rlp v0.2.1 (*)
│ │ ├── impl-serde v0.3.2 (*)
│ │ ├── primitive-types v0.7.3
│ │ │ ├── fixed-hash v0.6.1 (*)
│ │ │ ├── impl-codec v0.4.2
│ │ │ │ └── parity-scale-codec v1.3.7
│ │ │ │ ├── arrayvec v0.5.2
│ │ │ │ ├── bitvec v0.17.4 (*)
│ │ │ │ ├── byte-slice-cast v0.3.5
│ │ │ │ └── serde v1.0.152 (*)
│ │ │ ├── impl-rlp v0.2.1 (*)
│ │ │ ├── impl-serde v0.3.2 (*)
│ │ │ └── uint v0.8.5
│ │ │ ├── byteorder v1.4.3
│ │ │ ├── crunchy v0.2.2
│ │ │ ├── rustc-hex v2.1.0
│ │ │ └── static_assertions v1.1.0
│ │ └── uint v0.8.5 (*)
│ ├── hex v0.4.3
│ ├── hmac v0.7.1
│ │ ├── crypto-mac v0.7.0
│ │ │ ├── generic-array v0.12.4
│ │ │ │ └── typenum v1.16.0
│ │ │ └── subtle v1.0.0
│ │ └── digest v0.8.1
│ │ └── generic-array v0.12.4 (*)
│ ├── pbkdf2 v0.3.0
│ │ ├── byteorder v1.4.3
│ │ ├── crypto-mac v0.7.0 (*)
│ │ └── rayon v1.6.1
│ │ ├── either v1.8.0
│ │ └── rayon-core v1.10.1
│ │ ├── crossbeam-channel v0.5.6
│ │ │ ├── cfg-if v1.0.0
│ │ │ └── crossbeam-utils v0.8.14
│ │ │ └── cfg-if v1.0.0
│ │ ├── crossbeam-deque v0.8.2
│ │ │ ├── cfg-if v1.0.0
│ │ │ ├── crossbeam-epoch v0.9.13
│ │ │ │ ├── cfg-if v1.0.0
│ │ │ │ ├── crossbeam-utils v0.8.14 (*)
│ │ │ │ ├── memoffset v0.7.1
│ │ │ │ │ [build-dependencies]
│ │ │ │ │ └── autocfg v1.1.0
│ │ │ │ └── scopeguard v1.1.0
│ │ │ │ [build-dependencies]
│ │ │ │ └── autocfg v1.1.0
│ │ │ └── crossbeam-utils v0.8.14 (*)
│ │ ├── crossbeam-utils v0.8.14 (*)
│ │ └── num_cpus v1.15.0
│ │ └── libc v0.2.139
│ ├── rand v0.7.3 (*)
│ ├── regex v1.7.0
│ │ ├── aho-corasick v0.7.20
│ │ │ └── memchr v2.5.0
│ │ ├── memchr v2.5.0
│ │ └── regex-syntax v0.6.28
│ ├── rlp v0.4.6 (*)
│ ├── secp256k1 v0.17.2
│ │ └── secp256k1-sys v0.1.2
│ │ [build-dependencies]
│ │ └── cc v1.0.41
│ ├── serde v1.0.152 (*)
│ ├── serde_json v1.0.91
│ │ ├── itoa v1.0.5
│ │ ├── ryu v1.0.12
│ │ └── serde v1.0.152 (*)
│ ├── sha2 v0.8.2
│ │ ├── block-buffer v0.7.3
│ │ │ ├── block-padding v0.1.5
│ │ │ │ └── byte-tools v0.3.1
│ │ │ ├── byte-tools v0.3.1
│ │ │ ├── byteorder v1.4.3
│ │ │ └── generic-array v0.12.4 (*)
│ │ ├── digest v0.8.1 (*)
│ │ ├── fake-simd v0.1.2
│ │ └── opaque-debug v0.2.3
│ ├── tiny-keccak v1.5.0
│ │ └── crunchy v0.2.2
│ └── wagyu-model v0.6.3
│ ├── base58 v0.1.0
│ ├── base58-monero v0.2.1
│ │ ├── async-stream v0.2.1
│ │ │ ├── async-stream-impl v0.2.1 (proc-macro)
│ │ │ │ ├── proc-macro2 v1.0.49 (*)
│ │ │ │ ├── quote v1.0.23 (*)
│ │ │ │ └── syn v1.0.107 (*)
│ │ │ └── futures-core v0.3.25
│ │ ├── futures-util v0.3.25
│ │ │ ├── futures-core v0.3.25
│ │ │ ├── futures-macro v0.3.25 (proc-macro)
│ │ │ │ ├── proc-macro2 v1.0.49 (*)
│ │ │ │ ├── quote v1.0.23 (*)
│ │ │ │ └── syn v1.0.107 (*)
│ │ │ ├── futures-task v0.3.25
│ │ │ ├── pin-project-lite v0.2.9
│ │ │ ├── pin-utils v0.1.0
│ │ │ └── slab v0.4.7
│ │ │ [build-dependencies]
│ │ │ └── autocfg v1.1.0
│ │ ├── thiserror v1.0.38
│ │ │ └── thiserror-impl v1.0.38 (proc-macro)
│ │ │ ├── proc-macro2 v1.0.49 (*)
│ │ │ ├── quote v1.0.23 (*)
│ │ │ └── syn v1.0.107 (*)
│ │ ├── tiny-keccak v2.0.2 (*)
│ │ └── tokio v0.2.25
│ │ ├── bytes v0.5.6
│ │ ├── futures-core v0.3.25
│ │ ├── memchr v2.5.0
│ │ └── pin-project-lite v0.1.12
│ ├── bech32 v0.6.0
│ ├── byteorder v1.4.3
│ ├── crypto-mac v0.7.0 (*)
│ ├── ethereum-types v0.9.2 (*)
│ ├── failure v0.1.8
│ │ ├── backtrace v0.3.57
│ │ │ ├── addr2line v0.14.1
│ │ │ │ └── gimli v0.23.0
│ │ │ ├── cfg-if v1.0.0
│ │ │ ├── libc v0.2.139
│ │ │ ├── miniz_oxide v0.4.4
│ │ │ │ └── adler v1.0.2
│ │ │ │ [build-dependencies]
│ │ │ │ └── autocfg v1.1.0
│ │ │ ├── object v0.23.0
│ │ │ └── rustc-demangle v0.1.21
│ │ └── failure_derive v0.1.8 (proc-macro)
│ │ ├── proc-macro2 v1.0.49 (*)
│ │ ├── quote v1.0.23 (*)
│ │ ├── syn v1.0.107 (*)
│ │ └── synstructure v0.12.6
│ │ ├── proc-macro2 v1.0.49 (*)
│ │ ├── quote v1.0.23 (*)
│ │ ├── syn v1.0.107 (*)
│ │ └── unicode-xid v0.2.4
│ ├── ff v0.6.0
│ │ ├── byteorder v1.4.3
│ │ └── rand_core v0.5.1 (*)
│ ├── hex v0.4.3
│ ├── rand v0.7.3 (*)
│ ├── rand_core v0.5.1 (*)
│ ├── ripemd160 v0.8.0
│ │ ├── block-buffer v0.7.3 (*)
│ │ ├── digest v0.8.1 (*)
│ │ └── opaque-debug v0.2.3
│ ├── rlp v0.4.6 (*)
│ ├── secp256k1 v0.17.2 (*)
│ ├── serde_json v1.0.91 (*)
│ ├── sha2 v0.8.2 (*)
│ └── uint v0.8.5 (*)
└── wagyu-model v0.6.3 (*)
Usually, Cargo tries to find a single common version of a library for all dependencies, but 0.7.x
and 0.8.x
are not compatible according to Rust's semver rules, so it includes the library twice. Of course it can't allow those two to be used with each other, as the results would be unpredictable.
While the problem is complicated and obscure, the solution is simple:
Use rand = "0.7.3"
in your Cargo.toml
until wagyu
gets upgraded to rand = "0.8.x"
.
You could open an issue in their issue-tracker about it, but it seems that the project as a whole didn't get maintained since over a year. Their website doesn't even exist any more. So be aware that this project might be abandoned.
Upvotes: 1