Rust Learning Record (Nightly)

Source: Internet
Author: User

2.1 Installation

$ curl-l https:///static.rust-lang.org/rustup.sh | sudo sh

2.2 Hello, world!

Create a project

$ mkdir ~/~/projects$ mkdir hello_world$ cd Hello_world

Create main.rs, current directory structure

projects/└──hello_world    └──main.rs

Writing code

fn Main () {    println! ( " Hello, world!. " );  }

Compiling main.rs in the terminal

$ RUSTC main.rs    //  compile

And now our engineering catalogue has become

projects/└──hello_world    ├──main    //  executable file    └──main.rs

Execute main, you can see the output of "Hello, world!."

// run the generated main execution file // output of Hello, world!

println! () is a macro of Rust, so long as it sees an exclamation mark, it is a macro that replaces the normal function.

2.3 cargo!

Cargo is a tool to help manage Rust projects.

Enter your project directory, create the SRC folder, and move the previous main.rs to the folder

$ mkdir src$ mv main.rs src/main.rs

Create a CARGO.TOML file

[Package]//Package section tells the Cargo program information (meta data)name="Hello_world"version="0.0.1"authors= ["Your name <[email protected]>"][[bin]]//tell Cargo to generate a binary executable filename="Hello_world"    //the name of the executable file

Execute the compile command to run the compiled executable file

$ Cargo Build    //  Compile code file   compiling Hello_world v0.  0.1 (file://Home/yourname/projects/hello_world)$./target/hello_world    //  Run the generated executable Hello, world!    // the output information

Current Project Catalog

projects/└──hello_world    ├──cargo. Lock     ├──cargo.toml    ├──main    //  Previous executable file generated with RUSTC     ├──src    │└── Main.rs    └──target    //  Execute the cargo build command after the generated folder         ├──build        ├── Deps        ├──examples        ├──hello_world    //  and main executable file        └──native

Rust Learning Record (Nightly)

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.