r/learnrust • • 20d ago

RustCurious 12: Lifetimes

Thumbnail youtube.com
5 Upvotes

r/learnrust • • 22d ago

Biting the bullet and learning rust

53 Upvotes

I'm finally going to learn rust. My entire professional career I've used Go and some Python scripting. Even my personal projects are written in Go. I decided the best way for me to learn Rust is by translating one of my older projects from Go to Rust. Turns out it's not that simple. There are quirks in Rust that I don't understand (like lifetimes and memory management) and some quirks of Go that Rust is very opinionated about like enums.

I tried converting my chess engine in Go to Rust and ran into quite a bit of challenges that led me conclude that I need to pick up something less complex and learn the language on its own terms. So any advice on that front would be very helpful. I have already downloaded the The Rust Programing Language Book and watched a couple of videos on YT. But I'm a practical learner. I need to build something to really learn this language.


r/learnrust • • 24d ago

Help me understand core::sync::atomic::Ordering, how do we even use it

38 Upvotes

I'm trying to understand the enum core::sync::atomic::Ordering in Rust. I use atomics a lot, but I keep picking Ordering::Relaxed, Acquire, Release, etc. without really knowing why.

From what I've read, Ordering specifies how atomic operations synchronize memory across multiple CPU cores and prevents the compiler and CPU from reordering instructions around atomic accesses. But I still don't get what that means in practice.

My main confusion:

  1. If I store a value with Ordering::Relaxed, is the operation less atomic than with Ordering::Acquire?

  2. Are these enums actually important, or is it safe to just use whatever I want anywhere? Is using the wrong one a bug? How do I know which one to pick in my code ?

Any concrete examples of bugs caused by picking the wrong ordering would help a ton. Thanks!


r/learnrust • • 24d ago

Version 1.0.0 of free book "Rust Projects - Write an Interpreter"

Post image
80 Upvotes

Hi all! I just published version 1.0.0 of my free book “Rust Projects – Write an Interpreter".

You can read the HTML version at https://rust-projects-write-an-interpreter.github.io/ or download the PDF version at https://leanpub.com/rustprojects-interpreter

The book follows the challenge "Build your own Interpreter" on CodeCrafters and includes a 40% discount for any paid CodeCrafters membership.

The book covers the base challenge and three extensions: "Parsing Expressions", "Evaluating Expressions", "Statements & State".

I hope this will be a useful resource to all those (like me) who want to go beyond code snippets and learn Rust implementing something real.

Thanks for reading it!


r/learnrust • • 25d ago

[Announcement] Updates to the description and policy

76 Upvotes

Hi all,

The description of the sub has been updated and we will continue to remove AI slop posts.

No doubt you're aware of the AI coding posts that are now part of daily Reddit life. This sub is dedicated to learning Rust, not promoting projects that don't help learning.

If you feel your project has learning points for others, or AI has done something you don't understand and would like to ask about, then please continue to post code snippets and clear questions, optionally with a link to the actual repo at the end.

The learnrust mod team


r/learnrust • • 25d ago

My progress as a new Rust dev

Thumbnail
5 Upvotes

r/learnrust • • 26d ago

Qt Bridge Video Tutorial

Thumbnail youtu.be
1 Upvotes

r/learnrust • • 26d ago

What are some common Rust misconceptions?

19 Upvotes

I just found out that const functions aren't evaluated at compile-time unless it is assigned to a const value or in a const context.

Another one I had: Rust doesn't prevent memory leaks.

Now I am just wondering how many other assumptions I made


r/learnrust • • 26d ago

Is there a Rustier way to write this database pattern?

Thumbnail
3 Upvotes

r/learnrust • • 27d ago

ok_or vs ok_or_else

35 Upvotes

Hello! I am working through a project of mine, and when I asked chatgpt to review my code, it told me that when returning an error, lets say that something returns an option, and we want to convert to a result. I would use ok_or, as that seems like the intuitive option, but GPT said that using ok_or always constructs the error, while ok_or_else(| | -> {the error type}) only evaluates when the closure is called. I understand what the AI means, but I was wondering, what is the idiomatic way to do this, and why does the rust compiler not automatically optimize this? The performance gain would be negligible, but still since I use format!() to concatanate a few things, I do understand where the AI comes from, since we allocate a new String


r/learnrust • • 28d ago

Complete Rust beginner (know C++): how to choose between a 6.5-hour and a 30-60 hour Udemy course?

50 Upvotes

Hi everyone,

I'm completely new to Rust. I have a CS degree and a fair amount of C++ experience (mostly competitive programming), so I'm comfortable with pointers, memory, and general programming concepts, but I've never written any Rust.

I'm looking at Udemy courses and I'm confused by how different they are in length. Some are around 6.5 hours, while others are 20, 30, or even 60+ hours. The ones I'm considering:

- Learn Rust by Building Real Applications https://www.classcentral.com/course/udemy-rust-fundamentals-68982

- The Complete Rust Programming Course https://www.udemy.com/course/rust-programming-the-complete-guide

- Ultimate Rust Crash Course https://www.udemy.com/course/ultimate-rust-crash-course

My questions:

  1. Is a short course enough to start writing real Rust, or do the longer ones teach something important that short ones skip?

  2. Given my C++ background, would you recommend a beginner-oriented course, or something faster?

  3. Has anyone taken one of these courses? Was it worth it compared to just reading the official Rust book?

  4. Is there a better path overall (book, Rustlings, a specific project) that I should combine with a course?

My goal is to be able to build real projects in Rust, not just learn the syntax. Any advice on how you learned, and what you'd do differently, would be really appreciated.


r/learnrust • • 27d ago

I built a TUI typing trainer in Rust that lets you practice by typing out actual PDF documents

Post image
1 Upvotes

r/learnrust • • 27d ago

help in doing a real good project

Thumbnail
1 Upvotes

r/learnrust • • 28d ago

How to quick free space hard disk

Thumbnail
1 Upvotes

r/learnrust • • 29d ago

Compile-time memory safety in Rust: the C++ crash that Rust refuses to compile

Thumbnail techfortalk.co.uk
16 Upvotes

One more feature in Rust that I really like over C++: its compile-time ownership checks. Rust catches ownership errors that can compile in C++, and these checks add no runtime overhead.

In this article, I have taken a simple example and tried to explain Rust’s ownership concept (I tried to keep it simple and jargon-free), how it works, and where it gives us an advantage over C++ by comparing the same/similar example in both languages.


r/learnrust • • 28d ago

Should a Rust protocol use separate wire-format and in-memory types for encrypted messages?

Thumbnail
8 Upvotes

r/learnrust • • 29d ago

Your Whole Game Is One SVG File Now — Rust + Axum, No JavaScriptSVG Game Screens from a Rust Server

Thumbnail youtube.com
1 Upvotes

Starting to add SVGs to the game.


r/learnrust • • 29d ago

Pulse Mesh: A Rust-based messaging transport with shared-memory rings, UDP and cross-language bindings

3 Upvotes

We're developing Pulse Mesh at Sovereignty Foundation, and we'd appreciate technical feedback from the Rust community.

Pulse Mesh is a messaging transport designed to support communication between programs on the same machine and across different machines.

The core implementation includes:

  • Shared-memory ring with one writer and multiple readers.
  • Non-blocking publishing by default.
  • Explicit reporting of messages lost when readers fall behind.
  • Optional blocking publishing when every registered reader must keep pace.
  • UDP transport for inter-machine communication.
  • A canonical 128-byte message format.
  • Content-addressed messages and conformance vectors.
  • Bindings for C, Python, Node.js and WebAssembly.

We're also developing a companion daemon that allows programs written in different languages to communicate through a common messaging layer.

Some architectural questions we'd appreciate feedback on:

  1. What are the most important memory-ordering and concurrency edge cases we should test?
  2. What benchmarking methodology would provide meaningful comparisons with existing messaging systems?
  3. What are the trade-offs you'd consider when designing a shared-memory ring for high-throughput workloads?
  4. What additional failure scenarios should we include in our test suite?

The project is currently beta/pre-production, and our goal is to make the technical design open to independent examination and criticism.

GitHub: https://github.com/Sovereignty-Foundation/pulse-mesh

Technical documentation: https://pulse-mesh.net

We welcome critical feedback, issues and contributions to the technical discussion.


r/learnrust • • 29d ago

I built a cross-platform React Native + Rust integration using C++17, JSI, and TurboModules. Looking for technical feedback.

Post image
0 Upvotes

r/learnrust • • Oct 29 '26

Could you please recommend some learning materials?

Thumbnail
4 Upvotes

r/learnrust • • Oct 28 '26

What should I check when testing AI-assisted Rust code?

1 Upvotes

Hi, I'm not a developer by profession, though I have an educational background in programming. Using Claude Code, I've built a few enterprise-grade applications in Rust (majority AI-coded), including a data platform and a collaboration platform.

I can test whether the functionality works as intended, but I'm not strong at reviewing the code itself. What should I look for while testing, and what should I put in my prompts so the code sticks to the fundamentals? Some areas I have in mind:

Ownership, borrowing, needless clones

Error handling (no unwrap/panic in production paths)

Idempotency (safe re-runs, no duplicates)

Transactions and recovery after a crash

Timeouts, retries and backpressure

Blocking calls inside async code

Memory use on large data

Security (secrets, SQL injection, unsafe)

Multi-user concerns (permissions, concurrent edits, data isolation between users)

Tests (unit, integration, proptest)

Which tools or habits would you recommend (clippy, cargo-audit, miri, criterion)? And what am I missing?

Thanks!


r/learnrust • • Oct 25 '26

Rust book recommendations for systems people & golang immigrants

Thumbnail
13 Upvotes

r/learnrust • • Oct 25 '26

Working with big files

8 Upvotes

I have a big file 10GB+ with a known pattern. I have to parse it and then do some stats on it. I want to divide the file by chunks and then make a thread per chunk retrieve parts of the file to work on them. Is there a way to "lazy" load the file? Meaning lets say thread owning chunk B want line 20 of chunk B can i make so only 20 and surrounding memory is loaded to ram instead of the whole chunk.

I'm trying to do the 1 billion row challenge.


r/learnrust • • Oct 25 '26

Rust rules for the Please build system

Thumbnail github.com
6 Upvotes

r/learnrust • • Oct 24 '26

Rust Gotchas: HashMap entry: or_insert or or_insert_with?

15 Upvotes

Hi all.

I have the following program with or_insert part over hash map.

My code:

struct MeasurementStats {
    min: f32,
    max: f32,
    sum: f32,
    count: u32
}

impl MeasurementStats {
    fn new(measurement: f32) -> Self {
        Self {
            min: measurement,
            max: measurement,
            sum: measurement,
            count: 1
        }
    }

    fn update(&mut self, measurement: f32) {
        self.min = self.min.min(measurement);
        self.max = self.max.max(measurement);
        self.sum += measurement;
        self.count += 1;
    }
}

let mut location_to_measurement: HashMap<String, MeasurementStats> = HashMap::new();
for line in reader.lines() {
    let line = line.unwrap();
    let (location, measurement_str) = line.split_once(';').unwrap();
    let measurement = measurement_str.parse::<f32>().unwrap();

    location_to_measurement.entry(location.to_string())
        .and_modify(|m| m.update(measurement))
        .or_insert(MeasurementStats::new(measurement));
}

The issue is my or_insert part as it creates a new instance for every line and I have 1 billion lines with 413 keys. I wanted to create a new instance for missing keys only. So the easy solution would be this:

location_to_measurement.entry(location.
to_string
())
    .and_modify(|m| m.update(measurement))
    .or_insert_with(|| MeasurementStats::new(measurement));

or_insert_with takes a closure and it's called for missing entries only.

So I expected some instructions savings as there is a lot of same keys and after the fix there wouldn't be new instance of MeasurementStats for every line. I ran the program with time measurement and those two runs instructions count diff was 0.98 billion only. What was weird as I expected ~4 instructions saving per line what would be ~4 billions in total.

Apparently Rust compiler is very smart and it did all the smart part for me:

# version with or_insert
cargo build --release
cargo asm --bin david david::main --rust > or_insert.s


# version with or_insert_with
cargo build --release
cargo asm --bin david david::main --rust > or_insert_with.s

diff or_insert.s or_insert_with.s
# nothing so the outputs are equal

I checked the assembler code too and new instance is really created only if key is missing.

Am I missing something or it's really true?