installation
The simplest way to install cargo is to use the Rustup script to obtain:$ curl-ss https://static.rust-lang.org/rustup.sh | sudo bash
You will get the latest version of Rust and the latest version of cargo. You need to run the script once a day to get the latest upgrade.
If you are using Windows, download the latest version of the 32-bit (rust and cargo) or 64-bit (rust and cargo) installation packages directly.
Alternatively, you can build cargo from the source code.
Let's get started.
Start a new project with cargo, using cargo NEW:
$ cargo New Hello_world--bin
We pass--bin because we are making binaries: if we only do a library, we will not pass--bin.
Check out what cargo generated for us: $ CD Hello_world$ tree.
.
├──cargo.toml
└──src
└──main.rs
1 directory, 2 files
This is everything we need to get started. First, take a look at the contents of the Cargo.toml file:
[Package] Name = "Hello_world" Version = "0.1.0" authors = ["Your Name <[email protected]>"]
This is referred to as "manifest", which contains all the metadata that cargo needs to compile the project.
The contents of src/main.rs are as follows:
fn Main () { println! (" Hello, world! "); }
Cargo generated a ' Hello World ' for us, let's compile it: $ cargo build
Compiling Hello_world v0.1.0 (File:///path/to/project/hello_world)
Run it:
$./target/debug/hello_world
Hello, world!.
We can also use cargo run to compile and run, one-step completion: $ cargo Run
Fresh Hello_world v0.1.0 (File:///path/to/project/hello_world)
Running ' Target/hello_world '
Hello, world!.
Deep learning
For more cargo details, please see the cargo manual.
Reprint Please specify source: http://blog.csdn.net/ucan23/article/details/45667187
Rust's Package Manager cargo