Rust's Package Manager cargo

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.