Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 292
picotard Avatar asked Jan 31 '19 21:01

picotard


People also ask

How do you run cargo?

To begin a Cargo Run, head to any outpost or seaport in a game — basically, head anywhere non-enemy, named NPCs can be found. Once there, find the Merchant Alliance representative (they're usually located right by the main ship dock) and speak to them.

How do you run after cargo build?

Because the default build is a debug build, Cargo puts the binary in a directory named debug. You can run the executable with this command: $ ./target/debug/hello_cargo # or .

What is cargo Command?

The cargo install command allows you to build and install a Rust binary. The command syntax is as shown: cargo build [options] create. You can install a crate from multiple sources such as –git, –path, and –registry. These flags allow you to change the source of the crate.


1 Answers

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.

like image 121
Francis Gagné Avatar answered Oct 01 '22 18:10

Francis Gagné