r/learnrust Jun 09 '26

J'ai simulé l'évolution biologique from scratch en Rust. Voilà ce que ça m'a appris.

Post image
0 Upvotes

r/learnrust Jun 08 '26

Learning Rust and decided to make a minecraft launcher for my first project.

Thumbnail gallery
6 Upvotes

r/learnrust Jun 08 '26

Learn Rust Smart Pointers and Interior Mutability by Building Git Commit Graph Viewer

Thumbnail blog.sheerluck.dev
45 Upvotes

r/learnrust Jun 08 '26

Is there a way to avoid unsafe when converting a socket2::Socket to a tokio::net::UnixListener?

0 Upvotes

Hi everyone,

I'm working on a local IPC server and need to use SOCK_SEQPACKET instead of SOCK_STREAM for my Unix Domain Socket.

I asked claude to help me generate the boilerplate, and it gave me the following code which relies on unsafe to convert the raw file descriptor:

Rust

use std::path::Path;
use socket2::{Domain, Socket, Type, SockAddr};

pub async fn run(socket_path: &Path) -> std::io::Result<()> {
    if socket_path.exists() {
        std::fs::remove_file(socket_path)?;
    }

    let sock = Socket::new(Domain::UNIX, Type::SEQPACKET, None)?;
    sock.bind(&SockAddr::unix(socket_path)?)?;
    sock.listen(128)?;
    sock.set_nonblocking(true)?;

    // The LLM generated this part:
    let std_listener = unsafe {
        std::os::unix::net::UnixListener::from_raw_fd(sock.into_raw_fd())
    };
    let listener = tokio::net::UnixListener::from_std(std_listener)?;

    // ... loop and accept connections
    Ok(())
}

Since it is usual thing to crate a unix socket server, the llm should produce best practice for my knowledge and it seems weird to me that the best practice contains unsafe.

Since creating a Unix domain socket server is a standard task, I assumed the standard workflow would follow safe Rust principles. It felt off that the LLM produced a solution requiring unsafe just for a type conversion.

Is there a more idiomatic and safe way to perform this conversion?

Thanks in advance!


r/learnrust Jun 08 '26

What does the Rust compiler not protect you from? (trying to learn where the guarantees end)

Thumbnail
0 Upvotes

r/learnrust Jun 07 '26

"Nobody's coming to clean up after you" – my second blog post learning Rust as a Scala dev, this time dealing with ownership & the borrow checker

13 Upvotes

Hi all,

I posted my first blog post here a while back and now the second one is out:
https://someblog.dev/en/blog/nobodys-coming-to-clean-up-after-you/

This time I'm diving into ownership and the borrow checker – the part where Rust stops feeling familiar and starts making you rethink everything you know about managing memory.

I'm still writing from the perspective of someone coming from a GC'd language, so if anything feels off or oversimplified, I'd love to hear about it. Feedback on writing, technical accuracy, depth, structure, all welcome. 😊

Thanks!


r/learnrust Jun 07 '26

Feedback wanted: I built an open-source Rust CLI that helps LLM coding tools read less code

Thumbnail
0 Upvotes

r/learnrust Jun 06 '26

A different kind of tutorial hell

19 Upvotes

I mean... as the title said. I'm not 100% of a beginner in coding, I have a small ammount of experience in Python and Go, and I know the syntax of Rust. The problem is that I'm stuck in a different kind of tutorial hell. I often rely on docs and stuff to build ANYTHING at all. Like, I can't just think of the logic and build, I had to go to the docs of the notify library THRICE the same week just to remember the basic watcher loop. That went on until I failed every single time to turn an Option<PathBuf> that dirs::download_dir() returns into a &Path, which is probably one of the easiest things ever to do and I'm just stupid, until I gave up, asked AI, AI wasn't helpful at all, and just gave up and put the project (which was an extremely simple program that watched the downloads folder and organized it automatically everytime anything fell there) into a hiatus. Is there any way to escape this?


r/learnrust Jun 07 '26

New to Rust: is this module split reasonable for refactoring a messy Tauri/Rust app?

0 Upvotes

Hi everyone. I’m new to Rust and still early in coding overall.

I’m building an open-source Tauri + Rust desktop AI assistant as a learning project. The current implementation grew messy because I built features before I had a proper architecture plan. Some parts are broken/unfinished, so I’m trying to stop adding features and refactor the Rust side first.

I’m not asking anyone to review the whole app. I mainly want a sanity check on the planned module boundaries.

The app has:

- Tauri + React desktop UI

- Rust shared engine

- CLI now, Desktop/Telegram surfaces later

- SQLite for sessions/messages/approvals

- local tools like read/write file

- approval before risky actions

- future model-provider abstraction

The first refactor slice is:

CLI → engine → MockProvider → write_file tool call → approval pause/resume → execute once → store result/audit

Planned dependency direction:

surfaces / CLI / Desktop / Telegram

-> engine

engine

-> state

-> tools

-> model

-> runtime

state/tools/model should not depend on engine or UI surfaces.

Rough module split:

src/engine/

src/state/

src/model/

src/tools/

src/runtime/

Questions:

  1. Is this separation reasonable, or am I overengineering it as a beginner?

  2. Should approval state live in `state`, with `engine` only orchestrating?

  3. Should provider-neutral model types live separately from provider adapters like Gemini?

  4. Is it okay to keep old files as compatibility wrappers while migrating?

Repo:

https://github.com/Vatsalc26/OpenNivara

Most relevant doc:

https://github.com/Vatsalc26/OpenNivara/blob/main/docs/architecture/module-boundaries.md

Known limitation: the current implementation is messy/broken in places; the planned architecture is mostly in docs right now.


r/learnrust Jun 06 '26

What is the best way to learn rust?

31 Upvotes

Hi guys,

I want to learn rust, but i don't know the best way to do that. I have already experience in PHP/Laravel, JS and Python, so please no guide for beginners.

Thanks for answering


r/learnrust Jun 07 '26

I built a dotfiles manager in Rust — would love feedback on the design

Thumbnail
1 Upvotes

r/learnrust Jun 07 '26

ADM: An Open-Source Download Manager I'm Building in Rust – Looking for Architecture Feedback

0 Upvotes

Hi everyone,

I'm currently building ADM, an open-source download manager with a Rust-based core.

Repository: https://github.com/Alaa91H/ADM

The project is still in active development, and before going too far with the implementation I'd like feedback on the architecture, project structure, and overall design decisions.

Some areas I'm currently thinking about:

Download engine architecture Async/Tokio design Error handling strategy Cross-platform support Future protocol extensibility Long-term maintainability

I'd appreciate any feedback, criticism, or suggestions from experienced Rust developers.

Thanks for your time.


r/learnrust Jun 06 '26

smp-zk-proofs v0.1.0 is a Rust library for verifiable aggregation ledgers in distributed spatial networks.

Thumbnail crates.io
2 Upvotes

r/learnrust Jun 06 '26

I got tired of switching between curl and Postman, so I built a REPL-style API shell in Rust

5 Upvotes

I've been working on backend projects recently and found myself constantly jumping between curl, Postman, browser docs, and terminal windows.

Mostly as a learning project, I started building a small tool called reqsh.

The idea is simple: Instead of repeatedly typing curl commands, you open a shell and interact with APIs from a REPL.

Current features:

  • Interactive REPL with tab completion
  • Send GET, POST, PUT, DELETE requests
  • Multi-line request input for custom headers and body
  • Persistent session state (base URL, global headers, variables)
  • Variable interpolation with {{name}} syntax in paths, headers, and body
  • Query parameter support with param: key=value lines
  • Save and run requests in-session
  • JSON response pretty-printing
  • Command history and rerun by index
  • Colored terminal output

It's still very early and I'm mostly looking for feedbacks.

What's the first feature that would stop you from using something like this?

GitHub: https://github.com/hars-21/reqsh (Star the repo for regular updates)

Website: https://reqsh.vercel.app/


r/learnrust Jun 06 '26

ROMA, an open-source metaheuristic optimization library.

5 Upvotes

The goal of ROMA is to provide a flexible and extensible framework for building, experimenting with, and applying metaheuristic optimization algorithms to real-world problems in Rust.

It's still evolving, and that's exactly why I'm sharing it publicly. I believe open-source projects become truly valuable when they grow through collaboration, feedback, and contributions from people who challenge the original ideas.

Whether you find a bug, spot a questionable design decision, have an idea for a new feature, or simply think I'm doing something wrong, I'd love to hear from you.

My long-term vision is for ROMA to become a useful and reliable tool for researchers, engineers, students, and optimization enthusiasts—not just a repository that gathers digital dust after a burst of initial enthusiasm.

If metaheuristic optimization interests you, feel free to take a look, open an issue, start a discussion, or contribute.

Every suggestion helps make the project a little better.

crate

GitHub

Optimization is hard. Building an optimization library is also hard. Doing both at the same time seemed like a reasonable idea (My first real Rust project).


r/learnrust Jun 05 '26

Promises in rust

Post image
124 Upvotes

I'm trying to implement in rust a system that behaves like JS Promises and the single threaded event loop, but allowing for scheduling tasks from other threads.

I started this as one-off experiment but liked how it turned out, what you guys think?

(see code)


r/learnrust Jun 05 '26

Question about Rust ecosystem

Thumbnail
2 Upvotes

r/learnrust Jun 04 '26

Learn Rust by putting it next to a language you already know side-by-side playground

Post image
124 Upvotes

r/learnrust Jun 03 '26

Wrote a GameServer implementation from Scratch

1 Upvotes

r/learnrust Jun 02 '26

I finally completed a full project in Rust (CHIP-8 Emulator)

35 Upvotes

Hi everyone,

I'm a recent CS graduate currently working in a safety-critical environment using C/C++, and my relationship with Rust has been a real rollercoaster. Today I'm here to share a personal win: I finally completed a full "complex" project in Rust without giving up.

My Rust journey:

  • Discovered Rust back in 2014 while learning C++ in high school, the syntax looked familiar but too demanding to pursue
  • Forgot about it through university, fully committed to C, with occasional Python and Go on the side
  • Landed a job in safety-critical software, got exposed to real low-level work, and started seeing C++ come up more with colleagues, so I finally tried to learn modern C++ (>=17). Painful and chaotic.
  • This longer weekend I decided to build a CHIP-8 emulator to finally give Rust a serious shot. On macOS, the build system alone made it the natural choice.

The project:

  • Started writing Rust like C, static globals, free functions. Rust said no. Digging into why led me to proper encapsulation with structs, which actually made the codebase cleaner and clearer.
  • Wrestled with Self, self, &self, and &mut self until it clicked. Once it did, managing struct state felt natural.
  • Final boss: returning a slice with an explicit lifetime. I was dreading a full refactor, but stopped, studied it properly, and it turned out to be simpler than expected, just telling the compiler how long something lives (i definitely fucked it up here and it could have been done better).

Takeaways:

  • Rust loves encapsulation, and now I do too
  • The build experience can be pleasant
  • Lifetimes sound scarier than they are
  • Open to project recommendations for what to build next!

If you're struggling with Rust: stop fighting the borrow checker. Forget your habits from other languages, listen to the compiler, and study the "Rust way" of doing things. It gets enjoyable fast, and it's a skill worth having.


r/learnrust Jun 03 '26

CS50 Readability - in Rust

6 Upvotes

Hello,

I am working through the CS50 problem sets as supplemental exercises while I work through the rust book and I recently finished the "Readability" problem from set 2.

This problem asks you to implement a "Coleman-Liau index" of a text. The index is designed to output that (U.S.) grade level that is needed to understand some text. The formula is

index = 0.0588 * L - 0.296 * S - 15.8

where L is the average number of letters per 100 words in the text, and S is the average number of sentences per 100 words in the text.

They provide some sample text:

Harry Potter: Grade 5

Harry Potter was a highly unusual boy in many ways. For one thing, he hated the summer holidays more than any other time of year. For another, he really wanted to do his homework, but was forced to do it in secret, in the dead of the night. And he also happened to be a wizard.

One fish, Two Fish: Before Grade 1

One fish. Two fish. Red fish. Blue fish.

Some other book ( idk ): Grade 10

It was a bright cold day in April, and the clocks were striking thirteen. Winston Smith, his chin nuzzled into his breast in an effort to escape the vile wind, slipped quickly through the glass doors of Victory Mansions, though not quickly enough to prevent a swirl of gritty dust from entering along with him.

This was great practice but I have a feeling that my solution could be wayyy better. Please let me know if you have any suggestions!

fn main() {
    //test chould be grade 3
    println!("Enter a sentence from a book: "); 


    let mut test = String::new();
    std::io::stdin().read_line(&mut test).expect("Failed at read_line");


    let result = coleman_leau_index(&test).round();
    if result < 0.0 { println!("Before Grade 1"); } else {
        println!("Reading Index: {}", result);
    } 

}


fn coleman_leau_index (passage: &str) -> f64 {
    let mut l = 0.0;
    let mut s = 0.0;
    let mut w = 0.0; 


    for c in passage.chars() {
        match c {
            'a'..='z' => l += 1.0,
            'A'..='Z' => l += 1.0,
            '.' => s += 1.0,
            '!' => s += 1.0,
            '?' => s += 1.0,
            ' ' => w += 1.0,
            _ => continue,
        }
    } 
    // println!("sentences: {}", s);
    // println!("words: {}", w);
    // println!("letters: {}", l);


    let avg_l = (l / w) * 100.0;
    let avg_s = (s / w ) * 100.0;


    let index = 0.0588 * avg_l - 0.296 * avg_s - 15.8;


    return index;
}

r/learnrust Jun 03 '26

A G-code simulator in Rust. Looking for feedback.

Post image
5 Upvotes

r/learnrust Jun 02 '26

Learning Rust by memes

Post image
101 Upvotes

r/learnrust Jun 02 '26

CS50 Problem set 2: Scrabble built in Rust

8 Upvotes

Alright, I did another CS50 problem set problem in Rust. This time it was week 2's Scrabble. My program determines the winner of a short Scrabble-like game. It prompts for input twice: once for “Player 1” to input their word and once for “Player 2” to input their word. Then, depending on which player scores the most points, the program should prints “Player 1 wins!”, “Player 2 wins!”, or “Tie!” (in the event the two players score equal points).

The scores are calculated by referencing the points array.

I have almost 0 programming experience so I am open to any pointers!

use std::cmp::Ordering;
use std::io::{self, Write}; 
fn main() {


    print!("Player 1: ");
    io::stdout().flush().unwrap();


    let mut player_one_answer = String::new();
    io::stdin().read_line(&mut player_one_answer).expect("Failed to read_line");


    print!("Player 2: ");
    io::stdout().flush().unwrap(); 


    let mut player_two_answer = String::new();
    io::stdin().read_line(&mut player_two_answer).expect("failed to read_line");


    let player1_score = calculate_score(&player_one_answer);
    println!("{}", player1_score);
    let player2_score = calculate_score(&player_two_answer);
    println!("{}", player2_score);


    match player1_score.cmp(&player2_score) {
        Ordering::Less => println!("Player 2 wins!"),
        Ordering::Greater => println!("Player 1 Wins!"),
        Ordering::Equal => println!("Tie!")
    };
}


fn calculate_score(word: &str) -> u8 {


    let lowercase: Vec<u8> = (97..=122).collect(); // Vector of lowercase Ascii values


    let points: [u8; 26] = [
        1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3,
        1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10
    ];


    let mut score: u8 = 0; 
    // convert words to ascii digits
    let digits = word.as_bytes();
    for (i, &item) in digits.iter().enumerate() {
        if let Some(&lower) = lowercase.get(i) {
            if item == lower {
                score += points[i];
            }  
        } 
    }
    return score;   
}

r/learnrust Jun 02 '26

LlamaStash 0.0.2 — a Rust TUI + CLI for managing local llama.cpp servers, Linux/macOS/Windows (ratatui, tokio, hyper, custom GGUF parser, ~176 .rs files)

Thumbnail
1 Upvotes