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

心已入冬 提交于 2020-01-11 10:23:12

问题


I'm trying to run the example code from this project. Following the instructions on the Cargo docs, I did the following:

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

cargo test should also have compiled the example according to the Rust docs.

Although cargo test executes successfully, when I change into the target/debug directory, I don't find an executable for ftp-get (which is the example code). The target/debug/examples directory is also empty.

What is the best way to go about running this example?


回答1:


Try the following:

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



回答2:


You can run a specific example with:

cargo run --example name_of_example

where name_of_example is the base filename (without .rs)

or to run it in release mode:

cargo run --release --example name_of_example

To pass arguments to the example:

cargo run --example name_of_example -- arguments go here

cargo run will automatically build (or rebuild) the program first if it's out of date.



来源:https://stackoverflow.com/questions/54469463/how-do-i-run-a-projects-example-using-cargo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!