Tooling around RustΒ  πŸ› οΈ πŸ¦€

Yannick

Guern

https://lafor.ge

@_Akanoa_

Rust Tool belt

Rustup

  • Fetch
  • Download
  • Install
  • Upgrade
  • Manage channels

Channels

  • stable
  • beta ( every 6 weeks )
  • nightly (every nights )

The tool belt

  • rust-std
  • rustc
  • cargo
  • clippy
  • rustfmt
  • rust-docs

rust-std

  • Collections (Vec, HashSet, HashMap)
  • primitive types and prelude
  • Monads
  • string manipulation
  • OS specifics
  • Network
  • Threads + sync
  • panic
  • memory management ( Allocation, transmutation)
  • and many more ...

rust-std

Rust can run without the rust-std, useful for embedded compilation (Β΅ Controllers, device drivers, IOT, ...)

The STD increases the weight of the final artifact

rust-std

Editions

  • v1
  • 2015
  • 2018
  • 2021
  • 2024 (coming soon)

rustc

rustc

Compile rust sources for a wide range of targets:

  • x86_64
  • ARM
  • exotic targets

rustc

  • Check the code correctness πŸ”
  • Apply Borrow Checker πŸ‘©πŸ»β€βš–οΈ
  • Build AST πŸ”¨
  • Compile to the target 🎯

What does it do ?

rustc

  • Explicit error messages 😲
  • Guide the developer to the solution βŒπŸ‘£πŸ‘£βœ…
  • Your best buddy for pair-programming πŸ’•
  • Not an upset wizard πŸ§™β€β™‚οΈ

Benefits

cargo

  • Package manager
    • fetch
    • update
    • add / delete

Β 

  • Task runner
    • cargo init
    • cargo build [--release]
    • cargo run [--release]
    • cargo publish
    • cargo install

Cargo.toml

[package]
name = "toto"
version = "0.0.1"
edition = "2021"

[dependencies]
tokio = "^1.28"

cargo-plugins

Extends cargo behaviors with useful utils

  • cargo watch : hot-reload on code changes
  • cargo upgrades : check for new crates versions
  • cargo upgrade : edit the Cargo.toml automatically
  • cargo msrv : finding the Minimum Supported Rust Version for a crate

clippy

  • Better than the Window's one πŸ’©
  • Detect suspicious code and unintentional errors
  • Several severity levels:
    • Deny β†’ Error triggered, certainly an error
      • arc_with_non_send_sync βœ‰οΈ
      • while_immutable_condition : loop ♾️
    • Warn β†’ Success but with warning (suspicious)

clippy - lint group

  • suspicious : maybe right, maybe not ...
// incomplete range
let a = 'a' .. 'z';

// completed range
let a = 'a' ..= 'z'

clippy - lint group

  • style : you can do better
// init
let mut a = 1;
let b = 2;

// repetition
a = a + b;


// better
a += b;

clippy - lint group

  • perf : you can write something faster
// useless reallocations
let mut vec1 = Vec::with_capacity(len);
vec1.resize(len, 0);

let mut vec1 = Vec::with_capacity(len);
vec1.resize(vec1.capacity(), 0);

let mut vec2 = Vec::with_capacity(len);
vec2.extend(repeat(0).take(len));


// much better
let mut vec1 = vec![0; len];
let mut vec2 = vec![0; len];

clippy - lint group

  • perf : you can write something faster (2)
// useless indirection
Box<Vec<Foo>>


// much better
Vec<Foo>

clippy - lint group

  • complexity : you can write something simpler
loop {
    let x = match y {
        Some(x) => x,
        None => break,
    };
    // .. do something with x
}


// is easier written as
while let Some(x) = y {
    // .. do something with x
};

rust-docs

  • Generate documentation from source code.
  • Create a static website to browse the documentation

crates.io

  • Rust packets are named crates
  • Only sources are fetched and built, no binaries
  • Reference package registry is crates.io
    • npm.js
    • maven central
  • Private repositories:
    • meuse by Mathieu Corbin @_mcorbin (Java)
    • kellnr (Smarty)
    • alexandrie (Rust)

IDE

  • rust-analyzer : vscode, vim, etc... (free)
  • intellj-rust : jetbrain IDE plugin ( free )

Thanks

@_Akanoa_

https://lafor.ge

Tooling around Rust

By akanoa

Tooling around Rust

  • 266