[英]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.