Install Rust on Mac OS
Rust first experience:
Why choose Rust?
There are three main visions for the Rust language:
- high security
- high performance
- High concurrency
The Rust language aims to develop highly reliable and fast software in an easy way.
The Rust language supports the use of modern language features to write some system-level and even machine-level programs
Installation process:
Install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
The middle process will let you choose the installation method: default installation method, custom installation, cancel installation.
Successful installation:
Cargo:
A Rust compilation and package management tool.
cargo --version
: View cargo tool version
After the above installation is complete:
source ~/.bash_profile
cargo --version
cargo 1.62.1 (a748cf5a3 2022-06-08)
cargo installed successfully.
create project
Create a Hello World project to experience it:
cargo new hello_workd
cd hello_workd/
tree .
.
├── Cargo.toml
└── src
└── main.rs
1 directory, 2 files
Open 'src/main.rs':
fn main() {
println!("This is Hello, world!");
}
compile
cargo build
Compiling hello_workd v0.1.0 (/Users/xxxxx/workstation/project/learn/rust/hello_workd)
Finished dev [unoptimized + debuginfo] target(s) in 1.33s
Run to view the results
./target/debug/hello_workd
This is Hello, world!
or:
cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/hello_workd`
This is Hello, world!
reference: