我如何 运行 使用 Cargo 的项目示例?

How do I run a project's example using Cargo?

我正在尝试 运行 示例代码 from this project。按照 Cargo 文档上的说明,我执行了以下操作:

git clone https://github.com/basiliscos/rust-procol-ftp-client
cd rust-procol-ftp-client
cargo run 
cargo test

cargo test 也应该根据 Rust 文档编译 the example

虽然 cargo test 执行成功,但当我切换到 target/debug 目录时,我没有找到 ftp-get 的可执行文件(这是示例代码)。 target/debug/examples 目录也是空的。

完成此示例的最佳方法是什么?运行

尝试以下操作:

cd rust-procol-ftp-client
cargo build --examples
./target/debug/examples/ftp-get

您可以运行一个具体的例子:

cargo run --example name_of_example

其中 name_of_example 是基本文件名(没有 .rs

或 运行 它处于发布模式:

cargo run --release --example name_of_example

向示例传递参数:

cargo run --example name_of_example -- arguments go here

cargo run 如果程序已过期,将首先自动构建(或重建)该程序。