【问题标题】:How do I run a project's example using Cargo?如何使用 Cargo 运行项目示例?
【发布时间】:2019-07-01 06:51:43
【问题描述】:

我正在尝试运行示例代码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 目录也是空的。

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

【问题讨论】:

标签: rust rust-cargo


【解决方案1】:

你可以运行一个特定的例子:

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 如果程序过期,将首先自动构建(或重建)程序。

【讨论】:

    【解决方案2】:

    尝试以下方法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 2022-11-18
      相关资源
      最近更新 更多