gpt4 book ai didi

rust - crate 找不到路径

转载 作者:行者123 更新时间:2023-11-29 08:28:39 25 4
gpt4 key购买 nike

我正在尝试使用这个箱子生成一个以太坊地址:https://docs.rs/ethkey/0.2.5/ethkey/

use ethkey::prelude::*;

fn main() {
let key = EthAccount::load_or_generate("~/", "passwd")
.expect("should load or generate new eth key");

println!("{:?}", key.address())
}

这是文档中的示例,它似乎不起作用。我收到以下错误:

cargo run Compiling ethkey v0.1.0 (/Users/samueldare/Documents/Code/Thor/ethkey) Finished dev [unoptimized + debuginfo] target(s) in 1.34s Running target/debug/ethkey thread 'main' panicked at 'should load or generate new eth key: Error(IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" }), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })', src/libcore/result.rs:999:5 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.

我使用 ~/ 作为在 rust 中生成 key 文件的最后一次尝试,但它似乎仍然不起作用。

我将不胜感激任何与此相关的建议

最佳答案

load_or_generate() 的第一个参数采用 std::path::Path没有结束斜线 ( '/' )。删除斜杠:

fn main() {
let key = EthAccount::load_or_generate("~", "passwd")
.expect("should load or generate new eth key");

println!("{:?}", key.address())
}

示例输出:

05:47 ethtest (master) ✗ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/ethtest`
Address(0x8248af6d1765e559509060b88e540a3567c42d20)
05:47 ethtest (master) ✗

关于rust - crate 找不到路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57201043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com