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)