Installation
Orestis Malaspinas
https://www.rust-lang.org/tools/install
Outil pour configurer et manager la chaîne de compilation de Rust.
Installation de la chaîne de compilation (toolchain):
curl https://sh.rustup.rs -sSf | sh
Quelques commandes importantes
$ rustup install stable # installation de la chaîne stable
$ rustup default stable # chaîne par défaut
$ rustup self uninstall # désinstallation
$ rustup install nightly # installation de la chaîne en développement
$ rustup update # mise à jour de la chaîne de compilation
rustc
: compilateur et éditeur de liencargo
: outil pour la compilation et gestion de dépendancesrustdoc
: documentationrust-(lldb|gdb)
: débuggerlibcore
/libstd
rustc
rustc
est écrit en Rust (en grande partie).
rustc --help
Hello World!
Dans un fichier hello_world.rs
.
fn main() { // présent dans tout programme Rust
println!("Hello, World!"); // macro d'affichage
}
Pour compiler, éditer les liens et exécuter
$ rustc hello_world.rs
$ ./hello_world
Hello, World!
rustc
.Permet l’installation d’outils (peut se faire avec rustup également)
$ cargo install clippy # conseil de "beauté du code"
$ cargo install rustfmt # formattage automatique du code
$ cargo new hello_world --bin # création projet
$ cd hello_world
$ cargo build # cargo check
Compiling hello_world v0.1.0 (file:///home/malaspor/hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 1.33s
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.05s
Running `target/debug/hello_world`
Hello, world!
$ ./target/debug/hello_world
Hello, world!
$ cargo build --release # compilation avec optimisations
Compiling hello_world v0.1.0 (file:///home/malaspor/Downloads/hello_world)
Finished release [optimized] target(s) in 0.35s
Cargo.toml
:
[package]
name = "hello_world"
version = "0.1.0"
authors = ["Your Name you@example.com"]
[dependencies]
Cargo.lock
:
[[package]]
name = "hello_world"
version = "0.1.0"