在Rust存储库中有一个名称中带有破折号“-”的包,我如何在Rust代码中“使用”?

8gsdolmq  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(98)

此问题在此处已有答案

crate name with hyphens not being recognized(2个答案)
Why is changing hyphenated crate names to underscored names possible and what are the rules for naming under such ambiguous scenarios?(1个答案)
crate name has a dash : unresolved import error(1个答案)
上个月关门了。
这篇文章是29天前编辑并提交审查的。
我想在rust代码中使用异步进程机箱/包。
https://github.com/smol-rs/async-process.git的函数。
在crates.io页面中,它说我可以将它放在我的项目的Cargo.toml中为:

[dependencies]
async-process = "2.0.1"

字符串
而在我的铁 rust 代号为:

use async_process::Command; // this fails to find the "crate"


这不管用。
在构建时,将检索并编译板条箱,但编译代码时会出现以下错误:

error[E0432]: unresolved import `async_process`
 --> build.rs:4:5
  |
4 | use async_process::Command;
  |     ^^^^^^^^^^^^^ maybe a missing crate `async_process`?
  |
  = help: consider adding `extern crate async_process` to use the `async_process` crate


我便试探着:

extern crate async_process;


并得到以下错误:

error[E0463]: can't find crate for `async_process`
 --> build.rs:4:1
  |
4 | extern crate async_process;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate


这是如何工作的?是对build.rs的一些限制吗?
我想要这样做的原因是,我正在使用build.rs生成一个命令来运行一个相当日志化的进程,并希望将其stdout记录到一个文件(或在运行时打印到控制台),async-process::命令提供了一种实现这一点的方法,也就是说,如果我可以使用它。

ht4b089n

ht4b089n1#

在货舱里。托姆,用破折号。

[dependencies]
async-process = "2.0.1"

字符串
在代码中,使用下划线。

use async_process::Command;


应该可以
如果有疑问,crates.io上的crate页面将在右侧列出应该在Cargo.toml中使用的名称。
当在代码中包含crate时,总是使用下划线而不是破折号。

相关问题