Skip to content
Sébastien Barbieri's Blog
Sébastien Barbieri's Blog

Partage d'expérience de développements de sites et d'applications, d'ux, d'apprentissage machine, de coaching…

Sébastien Barbieri's Blog

Partage d'expérience de développements de sites et d'applications, d'ux, d'apprentissage machine, de coaching…

Rust 1.99

Posted on 2026-11-072026-11-28 By scips

I don’t know why, but I really like Rust.

I like it, I did start trying to learn it, and at a point I got blocked and I couldn’t work further a kind of wall where my mind was not able to figure out how to do it in Rust. I was lost, couldn’t find my way. I was looking online to see that the answer doesn’t work with my version of Rust … And I gave up.

Few years later, I want my revenge.

Why Rust. I find it very elegant but Pascal and Go are also very elegant. What I like most in Rust is that it looks like the high level language, while being a very low level one. You write like one can write in javascript while being able to manipulate and allocating memory (like in C) but much more securely.

I also like the link with the web and the ability to build up part of your code in Rust and WASM it for the web. (My first attempt at learning Rust: https://github.com/scips/wasm-game-of-life)

Finally I’m the kind of guy who don’t hesitate to add in a C program a small ASM block to speed up part of the code for Real Time Programming. I had a lot of issue, memory issue, limit case, overflow, divide by 0… that I had to deal with. I’m glad I want through this because it helped me a lot to learn clean and safe programming. That’s probably what I found the most interesting, working with immutable items as much as we can, creating a totally predictable system.

Let see where this will lead us.

#newskillnovember

It’s just a pretext, but I needed some kick to start it again. So let start New Skill November!

NEW SKILL NOVEMBER

[an art nouveau painting in autumn colors of a woman playing the harp]

LEARN A NEW SKILL OR REBUILD AN OLD ONE; THE ONLY RULE: DO IT YOURSELF, DO NOT USE AI

Sketching, knitting, whittling, a musical instrument, a foreign language, a tricky video game, cooking, weaving, changing oil, riding a bike, painting, pixel art, website design, digital image editing, bookbinding, calligraphy, identifying mushrooms, embroidery, soldering, that one thing you've been putting off
Image from: https://mastodon.social/@0xabad1dea@infosec.exchange

One Rule: Don’t use AI!

So my go to will be to take a book, read-it, learn, try stuff…

I plan to update this Article with updates from my learning.

5 November

Here is the book I’m reading: https://doc.rust-lang.org/book/title-page.html I took a PDF version of the book.

Chapter 01

First surprise: Rust has a guaranteed backward compatibility. Just specify the edition in Cargo.toml and you are in.

So I’m learning Rust 2024 and not Rust 1.99 🙂

7 November

Trying to finish chapter 01, working late and after work, doesn’t help the learning of new skills. Let’s learn in the morning!

cargo is a “best practice tool” it helps generate code organisation and generic files (TOML) and automatically .git … but for some reason not in my case. Probably he detected I’m already inside a git repository … will need to deep dive there.

There’s a place for everything, and everything is in its place

It seems that cargo check is the tool to run in a file watcher continuous testing environment.

$ cargo build --release
   Compiling hello_cargo v0.1.0 (/Users/scips/Workspaces/Rust/RustBook/Chapter_01/hello_cargo)
    Finished `release` profile [optimized] target(s) in 0.77sCode language: Bash (bash)
$ ls -alh ./target/release/hello_cargo
-rwxr-xr-x@ 1 scips  staff   425K Nov  7 10:05 ./target/release/hello_cargoCode language: Bash (bash)

425 Kb ? For a “Hello, world!” … I found out there is a #![no_std] version: https://zenn.dev/zulinx86/articles/rust-nostd-101 that explain why the basic build takes a full floppy disk to have an “hello world” and how to write a very small hello world (useful for embed code)

fn main() {
    println!("Hello, world!");
}

Code language: Rust (rust)

I deep dived into the aarch64 assembly language too much, now I can write to memory and do syscall… absolutely not what I wanted to learn … let’s move one

Chapter 02

Mutable and immutable variable ! I’m really curious on how they do that as a variable is just a pointer to a memory spot.

And “::new” is a common name for a function that makes a new value of that type e.g. String::new().

Which means it’s a convention but one can create a Whatever::magic() that will create a new value and break the convention. Need to investigate that later.

Because the Cargo.lock file is important for reproducible builds, it’s often checked into source control with the rest of the code in your project.

I like this way of thinking, it’s really conceived for collaboration: code best practice, hints, standard directory structure, convention in naming and in code practice…

by the way just found out that syntax highlighting wasn’t working because of the VCL Dark Theme … switched back to Dark+

For random number generation the book is stuck to version 0.8 of rand:: crate.

In 0.10 use: https://docs.rs/rand/latest/rand/fn.random_range.html

    let secret_number:i64 = rand::random_range(1..=100);Code language: Rust (rust)

Range writing is quite strange but OK:

[1;100][1;100] is. written 1..=100, which means [1;100[[1;100[ should be like 1..100 or 1..=99.

The doc is embedded on demand ? cargo doc --open The doc is embedded on demand !

Screen capture of the doc generated for the whole project showing the guessing_game doc present but empty
Screen capture

I just write a code and the doc is generated (but empty) for my code too and the included library aligned with each version of the library … powerful !

Shadowing ?

let mut guess = String::new();
let guess: i32 = 32; //...Code language: Rust (rust)

Chapter 03

by default, variables are immutable.

Here we go!

How does RUST ensure data are immutable in memory or at compile time ? https://dev.to/amritsingh183/a-complete-guide-to-rust-ownership-lifetimes-and-memory-management-4j2a has part of the answer.

What the H… Saturating_add : https://doc.rust-lang.org/std/intrinsics/fn.saturating_add.html

Ensuring that 255+1 = 255

Nice but I would have loved a kind of meta around +

We have thus

let mut x: u8 = 255;
x.saturating_add_signed(1); // x == 255Code language: JavaScript (javascript)

Where we could have had

let mut x:8 = 255;
#[saturating_add]
x = x + 1;Code language: PHP (php)

But this would be less readable I think with the #[xxx]

Another option would be to have type it the type itself:

let mut x: saturated_u8 = 255;
x = x + 1; // x = 255Code language: JavaScript (javascript)

But it would have needed non native type.

I’m the kind of guy who used too much operator redefinition in C++ and that was relying to much on the side effect of if (x) … when x was an integer.

Unicode

let I_love_rust: char = '❤️'; // won't work
let I_love_rust: char = '❤'; // will work
// and this will work without snake_case warning :P
let ilove_rust: char = '❤';
println!("What I think of Rust so far: {}", ilove_rust);Code language: JavaScript (javascript)

Loops

Loops are simple with range and this is my way of writing the 12 days of Christmas song

fn twelve_days_of_christmas_lyrics() {
    let cardinals = ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eight", "Ninth", "Tenth", "E-le-venth", "Twelfth"];

    let mut day:usize = 0;
    let mut counting:usize = 0;

    for day in 0..cardinals.len() {
        print!("On the {} day of Christmas my true love sent to me", cardinals[day]);
        for counting in 0..=day {
            christmas_lyrics_per_day(counting);
        }
        println!("");
    }
}

fn christmas_lyrics_per_day(day:usize) {
    let sentences = [
       "Partridge in a pear tree",
       "Turtle doves",
       "French hens",
       "Collie birds",
       "Golden rings",
       "Geese a-laying",
       "Swans a-swimming",
       "Maids a-milking",
       "Pipers piping",
       "Drummers drumming",
       "Lords a-leaping",
       "Ladies dancing"
    ];
    let numbers = ["a", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"];
    print!(" {} {}", numbers[day], sentences[day]);
}Code language: Rust (rust)

How awful is it ?

And this is my fibonacci…

fn fibonacci(upper_boundary:u32) {
    let mut fib_0 = 0;
    let mut fib_1 = 1;
    let mut fib_2 = 2;
    print!("{fib_0}, {fib_1}");
    while fib_2 <= upper_boundary {
        print!(", {fib_2}");
        fib_0 = fib_1;
        fib_1 = fib_2;
        fib_2 = fib_0 + fib_1;
    }
    println!(" is the Fibonnaci suit <= {upper_boundary}");
}Code language: Rust (rust)

Chapter 04

Just make me remember C and ASM: stack & heap.

  • Known fixed size –> stack memory –> pushing value on the stack
  • Others –> heap memory –> allocating returns a pointer to the address
  • Each value in Rust has an owner.
  • There can only be one owner at a time.
  • When the owner goes out of scope, the value will be dropped.

Slices

Do not take ownership of the arguments unless the function need to.

Chapter 05

So far so good for the struct, but the ..notation is not that easy to keep along.

struct User{
    email: String,
    hashed_password: String,
    id: u64
}
//...
fn main() {
    let usr1 = User {
       // ....
    };
    let mut usr2 = User {
        id: usr1.id + 1,
        ..usr1
    };
}Code language: Rust (rust)

The ..usr1 will copy all the remaining value to the appropriate keys. And pay attention… email + hashed_password will be references to usr1. thus it will be “moved”.

So we cannot reuse usr1 after the copy, the data inside usr1 have moved!

11 November

Also the Struct Tuple notation and access to a struct tuple item may be confusing

struct Point(i32, i32, i32);
struct Orientation(f32, f32, f32);

struct Cube {
    origin: Point,
    orientation: Orientation,
    size: f32
}
// accessing specific information
println!("|c|={} ({},{},{})",cube.size, cube.origin.0, cube.origin.1, cube.origin.2)Code language: Rust (rust)

But we can add derived trait ?! Derived trait ???

It’s where I learned that in order to use dbg! I need to implement #[derive(Debug)] on every struct that will be used with dbg!

And now let’s add method to the struct … we are almost near object and classes

#[derive(Debug)]
struct Cube {
    origin: Point,
    orientation: Orientation,
    size: f64
}

impl Cube {
    fn volume(&self) -> f64 {
        self.face_area() * self.size
    }

    fn face_area(&self) -> f64 {
        self.size * self.size
    }
}Code language: PHP (php)

With a &self which is a shorter form of: self: &Self. How many language use self instead of this ? Php, Ruby, Smalltalk, Python and Delphi ❤️ . Where all the C derivatives (including java) use this. In Perl it was whatever you wanted 🙂 First parameter was the object and could me my $me … which was useful for poetry.

impl Cube {
    fn magic(size: f64) -> Self {
        Self {
            origin: Point(0.0, 0.0, 0.0),
            orientation: Orientation(0.0, 0.0, 0.0),
            size
        }
    }
}Code language: Rust (rust)

Chapter 06

The Enum and the null. Looks like a tale… a tale from the crypt 😜

Once upon a time there was a Sir, Sir Charles Antony Richard Hoare aka Tony Hoare who invented the very root of most of the programming language, algorithm and operating system … and even quick sort. But he also invented the most dangerous invention of all time … the null reference.

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object-oriented language (ALGOL). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn’t resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

So this null gave a lot of work to plenty of computer scientist all over the world, and still continue to give a lot of work.

Years later, on a wonderful afternoon in the San Francisco bay area, a Lawful good knight called Graydon Hoare … yes same name … was working at Mozilla to change the world and make the internet a beautiful place for everyone.

While working at Mozilla, Graydon was thinking that maybe, he can change the world even more by creating a language that doesn’t have all the issue he is struggling with every day, while working in computer science.

So he started working on the side, week-end, nights … we know how it goes.

And at some point he decided:

/*
Module: option

Represents the presence or absence of a value.

Every option<T> value can either be some(T) or none. Where in other languages
you might use a nullable type, in Rust you would use an option type.
*/Code language: Rust (rust)

See more info: https://github.com/graydon/rust-prehistory

I had been criticizing, picking apart, ranting about other languages for years, and making doodles and marginalia notes about how to do one “right” or “differently” to myself for almost as long. This lineage represents the very gradual coaxing-into-belief that I could actually make something that runs.

And Tony was a good OCaml programmer and OCaml is a very good language to write a compiler. And you need a compiler to write your own compiler.

In OCaml https://ocaml.org/docs/options Options, None and Some do exists. I think that’s where they came to Rust.

So, we will never know whether Tony Hoares and Graydon Hoares are related, but they have both contributed to the history of programming language. One building most of the algorithm we use today and the other one creating something really powerful and much more secure by design.

If let and match together with enum seems to be the key of Rust programming.

Chapter 07

14 November

Modules make me really think about .PM (Perl Modules) as there is no class and namespaces we are really in a simpler folder based – “module based” organization.

a rectangle with the title package contains 4 rectangle crate: One root, one library and then crate 1 and 2. Also there is a file in the package: cargo.tml
My understanding of package, library, binary and crate so far – edit

And for the file organisation linked to the package

5 files inside the package
src/main.rs is the root crate
src/lib.rs is the lib crate
src/bin/crate_1.rs is one binary crate
src/bin/crate_2.rs is another binary 
cargo.tml
My understanding of the file organization inside a package so far – edit
a package can only contain 0 to 1 library crate, must contain 1 cargo.tpl file and may have non or has many binary crate.
My understanding of package relations with crates and config file – edit

And for the module it’s pretty much like in Perl.

For instance:

use crate::garden::vegetables::AsparagusCode language: CSS (css)

means the following directory structure: src/garden/vegetables/aspargus.rs

With all the modules / package / public and private stuff, I’m eager to start an complete HTTP api with Rust… I need to put that in the todo list – brain at 110% – too much caffeine.

And I just discovered SQLX … to manage sql change with sqlx migrate CLI… just like in RoR … really that’s amazing for a so low level language. you can feel to power of the community around it.

Oh! Just discovered super … not parent, not * … just super

pretty similar to any other language use xxx::yyy::zzz as TTT; make zzz::anything accessible and TTT as an alias within the current scope.

Thinking about security while looking at external packages make me think about the https://crates.io/ weakness. Would it be possible to tell cargo to use a different “repository” – kind of proxy for enterprise to ensure they avoid back package centralized and ensure package review by security ?

front_of_house mod needs delcare the insertion of hosting mod as publicly accessible
pub mod hosting;

lib mod needs delcare the insertion of front_of_house mod with private access
mod front_of_house;

lib mod wants to use add_to_wait_list() need to make the crate accessible in the scope of the lib by using use crate::front_of_house::hosting then hosting::add_to_wait_list() will be accessible within the lib.rs
What I understand from Modules in Rust – edit

Chapter 08

    fn process_prompt_entry_match(prompt: &str, enterprise: &mut Enterprise) {
        let tokens: Vec<&str> = prompt.split_whitespace().collect();

        match tokens.as_slice() {
            // "Add <person> <anything> <department>"
            ["Add", person, _, department, ..] => {
                enterprise.add_people_to_department(person.to_string(), department.to_string());
            }
            // "List" department OR "List all"
            ["List", "all", ..] => {
                for department in enterprise.get_departments() {
                    print_department(department.to_string(), enterprise);
                }
            }
            ["List", department, ..] => {
                print_department(department.to_string(), enterprise);
            }
            _ => {
                // unknown or malformed command
            }
        }
    }

    fn print_department(department: String, enterprise: &Enterprise) {
        match enterprise.get_people_in_department(&department[..]) {
            Some(people) => {
                println!("In department: {}", department.to_string());
                for person in &people {
                    println!("{person}");
                }
            }
            None => {
                println!("no such department: {}", department.to_string());
            }
        }
    }Code language: Rust (rust)

Match and Options are really powerful and need to think differently. We should get used to the Option<> return type, and to handle it properly within a match ….

Also the &str[..] allow us to take a slice (but the full one) from a String easily.

26 November

Chapter 09

There is no exception in Rust 🙂

Also the easy split between the “dev” and the “release” mode using Cargo.toml is quite handy.

[profile.release]
panic = 'abort'Code language: JavaScript (javascript)

To do

To investigate later

WhatWhenPDCAResult
Compile an hello world without std on aarch64 with asm! in Rust – https://www.ryanbuckley.uk/writing/arm-m1-mac-assembly-hello-world/2027
Create a function inside a Type Whatever that create new items of that type with ::magic()11/11/2026DoneRust use struct + impl to implement function on top of a structure. the impl take methods with any name than can be used to generate an instance of the struct + methods with any method name (e.g. ‘magic’, ‘new’, ‘old’,…)
Understand how Rust can ensure variable are immutable (use asm inside Rust to modify variable and see if it’s at compile time of if there is a real protection bundled with the binary [I think it’s compile time])30/12/2026Planned
My son asked me where does RUST (the name) come from ?8/11/2026Donehttps://bugzilla.mozilla.org/show_bug.cgi?id=680521
Create an HTTP REST API based on Rust library structure with inspiration from: https://www.rustfinity.com/blog/create-high-performance-rest-api-with-rust2027To do
Investigate if it’s possible for a company to have an crates.io local proxy to ensure library usage and version tracking but also library internal distribution31/12/2026Donehttps://github.com/rust-lang/cargo/wiki/Third-party-registries
Propose a fix in the rust-book to summarize the module/submodule organization a bit … something like in the end you should obtain …31/12/2026Planned

Open Source Software development rust

Post navigation

Previous post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Follow me on Mastodon
©2026 Sébastien Barbieri's Blog | WordPress Theme by SuperbThemes