Skip to content

Latest commit

 

History

History
 
 

1_setup

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Environnement Setup

🎯 Objective

Make your Rust setup environnement ready

  • Initialize project
  • compile and run

📝 Setup project with cargo

Cargo is the Rust Package Manager
It manage dependencies, tasks, project creation, workspaces... (can be compare to Npm)

Create a new application

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
use cargo new --help for more options

How to build application ?

Launch compilation with cargo command:

cargo build

Look at newly created directories and files:

ls ./target/

A new debugdirectory 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

Compile and Run

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

How to test ?

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...

📝 Exercice

change the programm output with :

Hello, i am Crabby 🦀 !

💡 Notes

  • crab emoji is not an ASCII Char
  • String are stored Utf8 encoded in Rust

👏 Congrats

You have a working Rust setup !

Check the expected source code here

📝 Summary

What you have learned

  • How to intialize project with cargo
  • Build projet
  • Run project
  • Test project

📚 Additional resources

Next Part

🤙 Go to next part: Syntax