r/learnrust

Modeling a file system

I've been teaching myself programming primarily using Rust, and it's been a blast. I seriously enjoy its modern ergonomics and the feeling of safety it gives me. But I'm running into a situation where I think I have to use smart pointers, and that's a problem because I've never used them before, and reading about them in the book just kind of breaks my brain.

What I want to do is abstractly represent a file system, with a root directory that contains files and subdirectories. I tried to do this:

struct Directory<'a> {
    parent: Option<&'a Directory<'a>>,
    directories: HashMap<String, Directory<'a>>,
    files: HashMap<String, usize>,
}

Which compiles, but immediately runs into issues when I want to define methods to do things like insert subdirectories. I get a cavalcade of compiler errors that I don't have the first idea how to fix. In my mind, there shouldn't be an issue with dangling references, since the parent optional reference should only point to the parent, which owns the child. I guess the compiler can't prove this?

reddit.com
u/The-CyberWesson — 16 hours ago
▲ 105 r/learnrust+1 crossposts

Today I learnt #[expect()]

#[expect()] SHOULD BE TAUGHT IN THE FIRST YEAR OF ELEMENTARY SCHOOL!!!

#[allow()] should be prohibited, a crime punishable by death!

[forbid(clippy::allow_attributes)] should be the default Rust, not even needed to write!

reddit.com
u/ScotchW — 1 day ago
▲ 12 r/learnrust+1 crossposts

Zervo - Servo-backed web browser written in Rust.

Hey r/rust!

Over the last few days, I’ve been working on Zervo, my personal hobby project - experimental, lightweight web browser built from the ground up in Rust.

The goal of Zervo is simple: pair the modern, minimalist UX ideas pioneered by Zen Browser (vertical tabs, clean workspace, distraction-free layout) with Servo, the parallel, high-performance web rendering engine written in Rust.

Why Zervo? Why i'm even trying it?

  • 100% Rust Stack: Servo’s parallel rendering model (WebRender, parallel layout engine, Stylo CSS) makes it super fast and memory-safe.
  • Zen-Inspired Workspace: Vertical tab management, customizable sidebars, and clean canvas areas to keep browsing focused.
  • Lightweight Footprint: Avoiding heavy Chromium/Blink wrappers in favor of a lean, native Rust environment.
  • Just for fun: soon i'll become student at Ecole 42 Paris so i need something to do before the start, call it warm-up project. Also it's a good way to learn Rust (I fell in love with it).

Current Status & Tech Details

  • Engine: Servo (embedded via Rust bindings)
  • UI Framework: Custom native Rust UI shell mapping seamlessly to Servo’s WebRender pipelines
  • Target Platforms: Linux, macOS, and Windows

It’s still in early development, so rendering complex Web APIs and heavyweight JS frameworks is an ongoing effort alongside Servo’s upstream progress. However, basic page rendering, navigation flows, and vertical UI layouts are working (not without bugs lmao, but i'm working on it). I'll open the source code when it becomes at least alpha-stage ready for testing. You're welcome if you want to contribute.

And yeah, i do use AI but not to "code", instead to ask and learn (and write parts of this post). All you see on screen is my code, written by hand, except Servo code and some cargo deps for making it possible.

▲ 72 r/learnrust+7 crossposts

My Rust engine performance

4 physics simulation with increasing physics body count

u/IamRustyRust — 3 days ago

I just started learning Rust, but &, !, str, and String are melting my brain

I’ve just started learning Rust, and I keep getting lost in all the little distinctions: when to use `&` and when not to, why some things end in `!`, `str` vs `String`, and so on.

I understand these probably fit together once ownership and borrowing click, but right now it feels like too many separate rules at once. Is there a clear beginner-friendly cheat sheet or visual summary that explains the common symbols and core types together?

reddit.com
u/KKTeX_LaTeX3 — 3 days ago
▲ 3 r/learnrust+3 crossposts

synap.md — self-hosted, Obsidian-style Markdown notes app (heavy WIP, open source)

Hey there!

Building synap.md — a self-hosted, Obsidian-style Markdown notes app. Notes stay plain \`.md\` files on your own disk, no lock-in. Web app (Nuxt) + a native Tauri/Rust desktop client that syncs against your own server, offline-capable.

Still WIP with rough edges, but usable — and I'd genuinely love contributors, especially if local-first sync or Rust interests you.

Repo: https://github.com/BungeeDEV/synap-monorepo (MIT)

u/Miserable_Function25 — 2 days ago

Rust: identity and meaning

Still wrapping my head around this strange language.

Is it fair to say that rust dissolves meaning and identity? Hear me out.

When you talk about variables, a conventional understanding is "this named thing represents a human-readable alias to a thing stored in memory".

When you talk about types, a conventional understanding is "it represents an object type or primitive type, where primitives have language attached behaviour and sizing, while object types can be extended by a language user".

When you talk about objects, a conventional understanding is "it represents a struct + methods, has instance and expected type"

Rust breaks every assumption:

- variable charges identity during lifetime, as data ownership itself moves: it's not just variable has a new value, referencing the variable without ownership does not have a runtime meaning

- rust does not have conventional object types: it has traits. It feels like interfaces, but without intermediate type: you instantiate directly from struct definition, traits are separate.

- rust does not treat objects as having a type, it treats them as a bag or traits. So if you have not defined "quak" and "meow" combination as a named trait, rust is absolutely fine with it. This is similar to class implementing multiple interfaces, but a different order: multiple interfaces attach to a struct, and there's no way to enforce the combination is coherent.

Sounds like minor difference, but it flips the order of how systems are designed: conventionally, you design what you want the system to do first, and then choose structure to implement it. In Rust, bottom up design prevails.

So, do you think there should be a higher level language on top of Rust that defines meaning, ontology and business rules?

reddit.com
u/Single-Blackberry866 — 3 days ago
▲ 4 r/learnrust+2 crossposts

New to Dioxus and Rust. Any tips about getting started?

Hey, I'm a webdev. I previously approached my project with JavaScript. I'm familiar with the js ecosystem.

I put a fair bit of consideration and in contrast to my JavaScript-approach, I'd like to investigate Dioxus.

I'm not completely new. I've dabbled in Rust before. I have read a lot of the docs and I'm sure there is much more to learn and practice.

What advice would you give to getting started with the Rust ecosystem approach?

Similar to a lot of languages there are considerations for things like tests. So it would be helpful to compare the options. As well as any other best-practices and nuances.

In relation to my project, I'm particularly interested in the tooling available in Rust for formal verification.


Just to be clear, im not here to waste your time on my slop, but if you want to see what I've got so far (practically nothing):

u/Accurate-Screen8774 — 4 days ago
▲ 18 r/learnrust+3 crossposts

I Built a Free Open Source E2EE Journal Web App

Github: https://github.com/MrSheerluck/smbl-journal

I built a free, open-source, end-to-end encrypted text journal.
The goal is to make journaling as simple as possible. The entire text-based journal is free with no limits.
Entries are encrypted on the client before being stored, so the server never receives plaintext journal content.

The project is open source and available on GitHub.
Built with SvelteKit, Rust, and SQLite.

journal.smbl.dev
u/lazyhawk20 — 4 days ago
▲ 818 r/learnrust+1 crossposts

iStillLoveProgrammingButMyLoveIsNotForEveryone

u/_w62_ — 7 days ago

Can you verify my understanding of how Vec<T> resizes in memory?

I noticed that Vec capacity grows dynamically when pushing data.

Is my mental model accurate? When the buffer is full, does it allocate a new, larger memory region elsewhere on the heap, move the elements over, and free the old block specifically to avoid overwriting or corrupting adjacent heap data?

reddit.com
u/conceptcreatormiui — 6 days ago
▲ 19 r/learnrust+2 crossposts

tokio_with_wasm – write async Rust once, run it natively AND in the browser (spawn_blocking included)

If you've ever tried to take an async Rust codebase to the web, you know the pain: tokio just doesn't work on wasm32-unknown-unknown. No threads, no timers, no runtime. You end up littering your code with #[cfg(target_arch = "wasm32")] and rewriting half your task logic around wasm-bindgen-futures.

We built tokio_with_wasm to fix this with one line:

use tokio_with_wasm::alias as tokio; // THIS LINE
use std::time::Duration;

let async_handle = tokio::task::spawn(async { fetch_data().await });
let blocking_handle = tokio::task::spawn_blocking(|| heavy_work());
tokio::time::sleep(Duration::from_secs(1)).await;

That's it. On native targets it resolves to real tokio. On the web, it swaps in a drop-in mimic built on JavaScript web APIs — same module names, same patterns, same code.

Highlights:

  • spawn_blocking() actually works in the browser. It runs your blocking/compute-heavy code in a pool of Web Workers, and the pool auto-scales with the number of parallel tasks. Real parallelism, in a browser tab, from unmodified tokio-style code.
  • spawn**,** yield_now**,** sleep**,** interval**,** JoinSet — the familiar surface is there. Async tasks ride the JS event loop instead of a custom runtime, so nothing fights the browser.
  • We see this as a bridge, not a forever solution: once wasm32-wasi + wasi-threads mature, you shouldn't need it. Until then, this is how you ship.

It's MIT licensed, and there's a demo GIF in the README showing async + blocking tasks running side by side in a browser.

Repo: https://github.com/cunarist/tokio-with-wasm

Fair warning: spawn_blocking on the web needs nightly + atomics target features + COOP/COEP headers for SharedArrayBuffer, and you should avoid panics (no unwinding on wasm32-unknown-unknown). Small price for writing your async code exactly once.

u/Cunarist — 5 days ago
▲ 0 r/learnrust+1 crossposts

Rust discourages OOP style code?

I'm building a tree builder struct (with a `build()` method) that has multiple fields that I want to be able to mutate. It seems Rust does not like it when I attempt to mutate multiple fields of that struct.

It seems functional/composition style is much favored over using struct fields. Is this the way I should be thinking about design patterns in Rust? Should I avoid OOP wherever possible?

I prefer OOP because it does result in cleaner code where I don't have to pass in every variable to functions.

reddit.com
u/Accurate_Gift_3929 — 9 days ago
▲ 12 r/learnrust+3 crossposts

Anyone know how to fix this??

This glitching in a same spot started to happen ever since my ram got upgraded from 16 to 32 and happens every 30 or so seconds. My fps upgraded a ton but this thing is unplayable. Anyone can help?

u/Own_Researcher_5885 — 8 days ago
▲ 108 r/learnrust

New book: Learn Rust Programming Today

My new book Learn Rust Programming Today has been published a few weeks ago. It is intended for software developers who already know how to program, and want to learn Rust. You can see the outline of the book and some sample content on the book's home page at Learn Rust Programming Today.

Most programming books will present you with isolated examples of language syntax, leaving you to complete the picture yourself when you actually need to get stuff done. Learn Rust Programming Today takes you on a complete journey from the start to the finished program that you can use, learning the necessary features of Rust on the way. It doesn't replace "The Book", but rather complements it.

During the course of the book you will build Today, a Rust command-line application that shows things that happened on this day in history (historical events, births of notable people, and so on) from various sources. You will also extend the program to handle days that are observed annually, such as Pi Day, and recurring events. You will also be able to add your own events.

The book examples are available at https://github.com/coniferprod/learn-rust
The Today program has its own repo: https://github.com/coniferprod/today-rs

You can ask any questions about the book in this thread, and I'll do my best to answer them.

u/coniferprod-0x01 — 9 days ago

Confusion to choose which language

I am confused to choose which language c++ or rust for my trading bot can you any one tell me which one I choose to develop my trading bot i have basic understanding of c++ and complete beginners in rust but 8 have prior experience with mern stack web development and python and socket programming in node.js

reddit.com
u/No-Nose5014 — 7 days ago
▲ 33 r/learnrust+2 crossposts

Ruby vs. Rust for a hobby programmer. Which one should I pick?

Hey everyone,
I'm looking to learn programming purely as a hobby (definitely not looking for a career change). I've tried out a bunch of different languages, including Python, which honestly didn't really click for me, but the two that I found super cool and really enjoyed are Ruby and Rust.
I'm well aware of how completely different they are. One is high-level and expressive, the other is system-level and super performant. Even with those differences, I'm equally interested in both and can't decide where to start.
Long term, I'd love to build a mix of side projects just for fun, like:

A simple Web App / REST API

A real-time chat application

Maybe some Desktop Apps down the road

Since my main goal is just to have fun, learn, and build cool stuff, which one would you recommend starting with?
Appreciate any thoughts or advice!

reddit.com
u/Intelligent_Role_824 — 11 days ago
▲ 11 r/learnrust+6 crossposts

Built a terminal-first tool for working with HTTP APIs

Been working on a small side project for the last few months called reqsh.

The idea started because I was constantly jumping between curl commands, Postman, editing headers, copying tokens, changing base URLs... it just felt more annoying than it should.

So I ended up building a terminal-first HTTP REPL where you stay in one interactive session. You can save base URLs, keep headers around, use variables, organize requests and just experiment without rewriting the same command over and over.

It's written in Rust and still pretty early, but people have started opening PRs which has been really cool to see.

Not trying to replace every API client out there. I just wanted something that fits the terminal workflow better.

I'd genuinely love some feedback from people who spend a lot of time working with APIs. What's missing? What feels awkward? Or is there something you wish tools like this did better?

GitHub: https://github.com/hars-21/reqsh
Website: https://www.reqsh.dev/

reqsh.dev
u/YesterdayOk921 — 7 days ago

Free Rust quizzes/contests with code snippets, hints, tests and explanations

Instead of reading Rust explanations and still blanking on ownership and lifetimes while writing code, practice for free with short multiple choice quizzes. Pick an answer, use hints if needed and get a clear explanation.

https://cratery.rustu.dev

No account needed, progress stays in the browser. Topics include ownership, borrow checker, lifetimes, traits, concurrency, smart pointers, macros, error handling, iterators.

You can also make your own quests and share a link if that is useful for study groups.

I am adding more questions and want to fill the thin spots first

u/capitanturkiye — 9 days ago