![](/img/trans.png)
[英]How do I make a structure generic in Rust without higher kinded type (HKT) support?
[英]How do I use the functionality of a Rust crate that has CLAP without using the command line?
新手在這里,如果這是一個愚蠢的問題,請道歉。
我想在我的代碼中使用wagyu crate 的功能。 這個板條箱具有命令行功能,所以我可以從命令行運行代碼,但我似乎無法從我自己的代碼中引用它。
我嘗試了 2 個選項:
對於第 2 項,我嘗試過:
use wagyu::cli::ethereum;
fn main() {
let m: String = String::from("sunny story shrimp absent valid today film floor month measure fatigue pet");
// Returns the address of the corresponding mnemonic.
let passphrase = "";
let pathway = "m/44'/60'/0'/0";
let address = ethereum::from_mnemonic(m, passphrase, pathway);
println!("phrase: {:?}", address);
當我嘗試構建此代碼時,出現以下編譯錯誤:
error[E0425]: cannot find function `from_mnemonic` in module `ethereum`
--> src\main.rs:37:29
|
37 | let address = ethereum::from_mnemonic::<>(s, passphrase, pathway);
| ^^^^^^^^^^^^^ not found in `ethereum`
但是我通過檢查ethereum.rs文件中的代碼知道有一個名為“from_mnemonic”的公共 function(在第 88 行定義)。
有誰知道為什么我不能稱之為 function? 或者,是否有一種簡單的方法可以在不使用命令行界面的情況下使用具有 clap 依賴項的 crate?
非常感謝。
from_mnemonic
function 應該這樣調用:
use wagyu::cli::ethereum::EthereumWallet;
use wagyu_ethereum::network::Mainnet;
use wagyu_ethereum::wordlist::English;
fn main() {
let mnemonic: String = String::from(
"sunny story shrimp absent valid today. film floor month measure fatigue pet"
);
let passphrase = "";
let path = "m/44'/60'/0'/0";
let wallet = EthereumWallet::from_mnemonic::<Mainnet, English>(
mnemonic,
Some(passphrase),
path
).unwrap()
}
但是wagyu::cli::ethereum::EthereumWallet
不是 pub,所以你不能簡單地這樣做。 您必須從 github 下載wagyu
的源代碼並進行編輯,以便wagyu::cli::ethereum::EthereumWallet
公開。
我認為您必須做出的唯一改變就是替換它(在ethereum.rs
中):
struct EthereumWallet {
有了這個:
pub struct EthereumWallet {
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.