Make your Rust setup environnement ready
- Initialize project
- compile and run
Cargo is the Rust Package Manager
It manage dependencies, tasks, project creation, workspaces... (can be compare to Npm)
cd /your/projects/directory/
cargo new crabbyMove to your application directory :
cd crabby💡 Notes
Cargo create a git repository with all structure by default
usecargo new --helpfor more options
Launch compilation with cargo command:
cargo buildLook at newly created directories and files:
ls ./target/A new debugdirectory have been created in target
You can execute built file :
./target/debug/crabbyLaunch compilation with release profile:
cargo build --releaseYou have a new release directory in ./target
ls ./target
.
..
debug
releaseA common way to run code when developing is to use cargo run
cargo run
Compiling crabby v0.1.0 (/your/project/crabby)
Finished dev [unoptimized + debuginfo] target(s) in 0.43s
Running `/your/project/crabby/target/debug/crabby`
Hello, i am Crabby 🦀 !cargo compiles with debug profile if needed and run compiled program
Launch cargo:
cargo test
Finished test [unoptimized + debuginfo] target(s) in 0.01s
Running unittests src/main.rs
running 0 tests❗ No test are writtien yet...
change the programm output with :
Hello, i am Crabby 🦀 !💡 Notes
- crab emoji is not an ASCII Char
- String are stored Utf8 encoded in Rust
You have a working Rust setup !
Check the expected source code here
What you have learned
- How to intialize project with cargo
- Build projet
- Run project
- Test project