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 crabby
Move to your application directory :
cd crabby
💡 Notes
Cargo create a git repository with all structure by default
usecargo new --help
for more options
Launch compilation with cargo
command:
cargo build
Look at newly created directories and files:
ls ./target/
A new debug
directory have been created in target
You can execute built file :
./target/debug/crabby
Launch compilation with release profile:
cargo build --release
You have a new release
directory in ./target
ls ./target
.
..
debug
release
A 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