Crate 找不到路径 [英] Crate cannot find path

查看:90
本文介绍了Crate 找不到路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此 crate 生成以太坊地址:https://docs.rs/ethkey/0.2.5/ethkey/

I am trying to use this crate to generate an ethereum address: 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())
}

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

This is the example from the documentation and it doesnt seem to work. I get the error below:

cargo run 编译 ethkey v0.1.0(/Users/samueldare/Documents/Code/Thor/ethkey)在 1.34 秒内完成开发 [未优化 + 调试信息] 目标运行 target/debug/ethkey 线程 'main' 在 'should load or generate new eth key 时恐慌:Error(IoError(Os { code: 2, kind:NotFound,消息:没有这样的文件或目录"}),状态 { next_error:无,回溯:InternalBacktrace { 回溯:无} })',src/libcore/result.rs:999:5 注意:使用 RUST_BACKTRACE=1 运行显示回溯的环境变量.

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 中生成密钥文件的最后一次尝试,但它似乎仍然不起作用.

Ive use ~/ as a last attempt to generate the key file in rust, but it still doesnt seem to work.

我将感谢您对此的任何指示

I will appreciate any pointers with this

推荐答案

load_or_generate() 的第一个参数需要一个 std::path::Path 没有结束斜杠( '/' ).删除斜线:​​

The first argument to load_or_generate() takes a std::path::Path with no closing slash ( '/' ). Remove the slash:

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) ✗ 

这篇关于Crate 找不到路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆