如何在 Rust 中使用其他项目的依赖项?
How to use dependencies from other projects in Rust?
我已经将一个包列为我的依赖项。该包有几个我想使用的其他依赖项。我该怎么做?
这是我的 Cargo.toml 文件:
[dependencies.substrate-api-client]
git = "https://github.com/scs/substrate-api-client"
这是我导入模块的方式:
use clap::{load_yaml, App};
这是我面临的错误:
error[E0432]: unresolved import `clap`
--> src/main.rs:17:5
|
17 | use clap::{load_yaml, App};
| ^^^^ use of undeclared type or module `clap`
尽管如此,我上面列出的依赖项(substrate-api-client
) is having clap
as a dependency itself.
我也尝试过使用 extern crate
:
extern crate clap;
use clap::{load_yaml, App};
但它也不起作用并产生了以下错误:
error[E0463]: can't find crate for `clap`
此问题已得到解答 。
但是,应该注意的是,除非明确选择公开,否则 crate 的依赖项是它自己的。这是一个好方法。如果您出于自己的目的能够依赖 substrate-api-client
中的 clap
,如果 substrate-api-client
选择将 clap
的版本更新为包含以下内容的版本,则您的应用程序可能无法编译重大更改(您尚未在 Cargo.toml 中设置依赖项的标记/分支)。
我已经将一个包列为我的依赖项。该包有几个我想使用的其他依赖项。我该怎么做?
这是我的 Cargo.toml 文件:
[dependencies.substrate-api-client]
git = "https://github.com/scs/substrate-api-client"
这是我导入模块的方式:
use clap::{load_yaml, App};
这是我面临的错误:
error[E0432]: unresolved import `clap`
--> src/main.rs:17:5
|
17 | use clap::{load_yaml, App};
| ^^^^ use of undeclared type or module `clap`
尽管如此,我上面列出的依赖项(substrate-api-client
) is having clap
as a dependency itself.
我也尝试过使用 extern crate
:
extern crate clap;
use clap::{load_yaml, App};
但它也不起作用并产生了以下错误:
error[E0463]: can't find crate for `clap`
此问题已得到解答
但是,应该注意的是,除非明确选择公开,否则 crate 的依赖项是它自己的。这是一个好方法。如果您出于自己的目的能够依赖 substrate-api-client
中的 clap
,如果 substrate-api-client
选择将 clap
的版本更新为包含以下内容的版本,则您的应用程序可能无法编译重大更改(您尚未在 Cargo.toml 中设置依赖项的标记/分支)。