Rust cargo commands and features
Initial the project
The information of how to setup and initial the project and how to use cargo command.
Contents
- Install
- Language features
- Cargo
Install
- Install the latest stable version of Rust using
rustup -
Write and run a “Hello, world!” program using
rustcdirectly - Using a ! means that you’re calling a macro instead of a normal function
Language Feature
- Rust is an ahead-of-time compiled language
- Rust is a strong type check language
- Rust allows us to shadow the previous value with a new one
- This feature is often used in situations in which you want to convert a value from one type to another type
u32seen here is an unsigned32-bitinteger
let guess: u32 = guess.trim().parse().expect("Need a number");
Cargo
- Cargo is Rust’s build system and package manager
- building your code
- downloading the libraries your code depends on
cargo checkjust check the code can be complies does not produce an executablecargo buildonly build and produce an executable./target/debugcargo runbuild and runcargo build --releasebuild and optimizations for benchmark and productiontarget/releasecargo test -- sub-mod name