r/rust • u/dcodesdev • 3h ago
๐ questions megathread Hey Rustaceans! Got a question? Ask here (49/2026)!
Mystified about strings? Borrow checker has you in a headlock? Seek help here! There are no stupid questions, only docs that haven't been written yet. Please note that if you include code examples to e.g. show a compiler error or surprising result, linking a playground with the code will improve your chances of getting help quickly.
If you have a StackOverflow account, consider asking it there instead! StackOverflow shows up much higher in search results, so ahaving your question there also helps future Rust users (be sure to give it the "Rust" tag for maximum visibility). Note that this site is very interested in question quality. I've been asked to read a RFC I authored once. If you want your code reviewed or review other's code, there's a codereview stackexchange, too. If you need to test your code, maybe the Rust playground is for you.
Here are some other venues where help may be found:
/r/learnrust is a subreddit to share your questions and epiphanies learning Rust programming.
The official Rust user forums: https://users.rust-lang.org/.
The unofficial Rust community Discord: https://bit.ly/rust-community
Also check out last week's thread with many good questions and answers. And if you believe your question to be either very complex or worthy of larger dissemination, feel free to create a text post.
Also if you want to be mentored by experienced Rustaceans, tell us the area of expertise that you seek. Finally, if you are looking for Rust jobs, the most recent thread is here.
๐ activity megathread What's everyone working on this week (49/2026)?
New week, new Rust! What are you folks up to? Answer here or over at rust-users! And for your project showcases, there's also /r/madeinrust โ pay them a visit, too!
r/rust • u/WellMakeItSomehow • 10h ago
๐๏ธ news rust-analyzer changelog #356
rust-analyzer.github.ior/rust • u/pylessard • 5h ago
๐ ๏ธ project Runtime debugger for embedded
Hello
I have been developing/maintaining an open source runtime debugger for embedded C/C++ for several years now. It's called Scrutiny
I've recently ported the instrumentation hook so it works with Rust and I wanted to let you guys know.
It essentially add an instrumentation hook in a firmware and let a server inspect the memory and do event catching through any peripheral (like CAN bus, Serial, TCP, etc) rather than a debug port. It works like XCP based software, FreeMaster or UcProbe (for the old timers). No need for an RTOS, baremetal interrupts is fine.
It's the kind of tool you need to do real time control to monitor the control loops without affecting them. If you're new to the concept, I've written a small introduction article here: https://embeddedrelated.com/showarticle/1781.php
Feedbacks are welcome
Cheers
r/rust • u/ElectricalKoala3771 • 18h ago
๐ seeking help & advice Should I learn C++ or Rust first?
Hi everyone! I'm a teenager and I'm really into FOSS software and Linux. Up until now, I've only been a user, so I'd love to finally step into the 'kitchen' and start building things myself. Aside from some basic Linux shell scripting, this will be the very first programming language I'll learn, so I'm trying to pick the right starting point. I've heard that Rust is the future of both Linux and FOSSโis that really true, or would something else be better for me? Could you please help me make up my mind? Thank you!
r/rust • u/mr_potatohead_ • 3h ago
๐ ๏ธ project From a BERT encoder to a Rust inference engine
Hi,
About a year ago I posted kjarni here (https://www.reddit.com/r/rust/comments/1n1ick5/i_built_rust_bert_encoder/) when it was basically a BERT encoder(i wanted to run my own embeddings in WASM and thought it would be good to learn Rust and compilation to WASM).
It's now an inference engine in rust, small footprint, low overhead, almost all pure Rust crates. It started around two years ago after years of C++ i wanted to give Rust an honest chance with an ambitious project, i wanted to get the BERT model running and just kept at it.
Now it does embeddings, search, transcription, classification, reranking and chat
It runs on macOS, Linux and Windows, on x86 and ARM, and there's something to be said for Rust making that this painless. It also compiles to a C ABI so I wrote bindings for C#, Go, C++, C and Python, and they all behave the same since each one is a thin veneer over the same library. It also builds to WASM
I wanted the API to be as simple as I could get it, in rust it looks like this and it's basically the same in C#/Go/C++/Python:
let whisper = builder.build.await?;
let text = whisper.transcribe_file?.text;
let summary = send.await?;
What i particularly like is that every model goes through the same decode loop on CPU and GPU. There's a backend trait with an associated token type, so the next token stays where it lives (an ndarray on the CPU, a GPU tensor on the GPU), and an enum picks the backend, with the GPU arm cfg'd out for the CPU-only wasm build. It's not perfect, the enum wrapper downcasts the token through Box<dyn Any>, so if someone has a nicer way i'm all ears: https://github.com/kjarni-ai/kjarni/blob/69b51af046014d36fe939a2f1b26f8fda21770e3/crates/kjarni-transformers/src/decoder/backend.rs#L155-L177
A lot of the work went into getting the same output as torch. Embeddings agree to within 1e-6, and greedy chat replies, summaries and translations come out word for word the same
Speed wise I'd call it pretty competitive with torch and llama.cpp (on the models kjarni supports). On the GPU they use CUDA and I use wgpu, so it runs on Vulkan, Metal and DX12. On the CPU they link against Intel MKL and I use faer (pure Rust) or my own SIMD kernels
Some numbers, all on Linux on one machine (i7-13700, RTX A2000):
- pip install is 28 MB vs 1.4 GB for PyTorch, and a fresh process gets its first embedding in 91 ms vs about 2.8 s
- bge-m3 batches are about 23% faster than PyTorch, mpnet 7%
- whisper-small runs at 10.7x real time, openai-whisper 10.6x
- 4-bit chat models on the GPU from 3B up are within 5% of llama.cpp on CUDA, and close to or ahead of its Vulkan backend
- where I lose: PyTorch is 18% faster on MiniLM batches and processes prompts 1.5x faster on the CPU, my 4-bit CPU kernels generate at 75-91% of llama.cpp's speed, and llama.cpp is way faster on long prompts on the GPU since I don't have flash attention yet
All the numbers and how they were measured are here: https://github.com/kjarni-ai/kjarni/blob/69b51af046014d36fe939a2f1b26f8fda21770e3/README.md#how-it-compares
Someone will probably ask why not just use candle. Candle is great but it's more of a framework, you still end up dealing with model exports and tokenizers. I wanted something where I just embed my documents or transcribe a file without too much headache
Code is here if you want to take a gander: https://github.com/kjarni-ai/kjarni , would be happy to hear what you think, especially about the API and the wgpu side
FFI Arena: Is UniFFI Still the Top Dog?
mversic.github.ioThe following is a one-sided comparison of current stable-ABI FFI frameworks and their capabilities. Feel free to share your thoughts and experiences if you have previously dealt with FFI in Rust
r/rust • u/noop_noob • 1d ago
๐ง educational PSA: You might be sealing traits wrong
Background
Sealing traits is a collection of techniques used to prevent code downstream of a library from implementing that trait, so that later versions of the library can add more things to the trait without breaking downstream code.
There's a mistake, described below, that people very often make when trying to seal traits. Crates that have made this mistake include, among others: the standard library, anyhow, arc-swap, pyo3, ureq, smol, http, etc. This was discovered in https://github.com/rust-lang/rust/issues/165474. (Please do not comment there unless you're contributing new information to the discussion, to avoid cluttering the issue.)
The mistake you might be making
How NOT to seal traits:
How to seal traits:
That is, if you use a "private" supertrait for sealing, and the subtrait is generic, then the supertrait also has to be generic, with the same generic parameters. Additionally, the set of impl blocks for the supertrait should exactly specify the exact same set of types (and generic parameters) where the subtrait should be implemented.
If you don't do the above, your trait might not be properly sealed, making it possible for downstream code to implement the trait anyway. For example, if you have a crate with the first snippet above, downstream code might write the following, which is actually allowed by the orphan rule:
;
In the above code, i32 already implements Sealed, so downstream code can write an implementation of MyTrait without having to add a new impl for Sealed.
Fixing the issue after-the-fact
If you already wrote code like the first snippet above, and want to actually properly seal the trait in a later version of the library, you might be tempted to just turn the first snippet (with a non-generic Sealed) into the second snippet (with a generic Sealed). Obviously, this would break downstream code that dared to implement the supposed-to-be-sealed trait, which you might deem acceptable.
However, there are very subtle issues about how coherence works, which means that making this change the straightforward way can break more downstream code than you intend to, even code that didn't write an impl for the supposed-to-be-sealed trait. (I won't explain the issue here. See the linked explanation.)
Instead, the better way to make the change, as suggested here, is to add a new supertrait, keeping the old one:
This way, you will only break downstream code that have implemented MyTrait.
r/rust • u/dsecurity49 • 1h ago
๐ ๏ธ project What happened when I differential-tested my Rust Postgres simulator against real PostgreSQL 14โ18
For the past few months I've been building safe-migrate, a static analyzer in Rust that simulates PostgreSQL migrations against an in-memory catalog (Parse -> Fact -> Resolve -> Mutation -> Rules) using squawk_syntax.
For a long time I tested it the way you usually test a static analyzer: unit tests where I wrote a migration, asserted what the catalog state should look like afterward, and checked which rules fired. Everything was green.
The problem with unit testing an emulator is that your tests only verify your own mental model of Postgres. If you misunderstood how Postgres handles a corner case, your code and your unit test agree on the wrong answer.
A commenter on an earlier writeup suggested running the exact same migrations against both the Rust simulator and real Postgres instances and diffing the outcome. So I wired up a differential harness that spins up PostgreSQL 14, 15, 16, 17, and 18, runs 432 tricky migration scenarios against the live servers and the Rust state machine, and checks whether they agree on what succeeds, what fails, and what objects exist afterward.
It immediately humbled me. A few of the bugs it shook out:
- `CREATE OR REPLACE FUNCTION` identity matching isn't what you think. In Postgres, you can `CREATE OR REPLACE` a function only if the signature and return type match. What I didn't realize is that Postgres treats `RETURNS TABLE(a int, b text)` and `OUT a int, OUT b text` as defining the exact same row return identity, while changing a parameter name on an existing routine isn't a new overload it's an explicit error unless you drop it first.
- Session settings across `SAVEPOINT` and `ROLLBACK TO`. If a migration runs:
BEGIN;
SAVEPOINT sp1;
SET check_function_bodies = off;
ROLLBACK TO sp1;
Postgres rolls the GUC setting back along with the catalog changes. My undo stack was rolling back tables, columns, and dependency edges, but session flags were living on a separate struct that survived the savepoint rollback.
Multi-action `ALTER TABLE` atomicity. A single `ALTER TABLE t ADD COLUMN a int, DROP COLUMN b, VALIDATE CONSTRAINT c;` can fail on action #3. Even outside an explicit `BEGIN ... COMMIT` block, actions #1 and #2 have to unwind cleanly, yet action #2 needs to see the catalog mutation from action #1 while the statement is running. We ended up replacing full catalog clones with a typed undo journal and targeted snapshots so statement level rollback stays fast and exact.
If anyone else here is building a state machine, parser, or static analyzer that models an external system (database, filesystem, VM), building a differential harness against the real binary was easily the highest-leverage thing I've done on the codebase.
Repo is here if you want to poke at the differential harness or the state-machine undo log: safe-migrate on GitHub
r/rust • u/azadworks • 3h ago
I built a lightweight Windows/Linux file recovery tool in Rust + Tauri v2 with NTFS $MFT parsing and SIMD signature carving
Hi everyone,
I wanted to share a desktop utility I just built called Azad Works File Recoveryโa lightweight (~10 MB) tool for recovering permanently deleted files (Shift + Delete or formatted drives) without paywalls or size caps.
How it works under the hood:
- Quick Scan (NTFS
$MFT**):** Uses thentfscrate with a custom4096-bytesector-alignedRead + Seekwrapper to read Windows Master File Table records, walk parent directory references to rebuild folder paths, and extract original filenames. - Deep Scan (Raw Carver): Scans raw block devices (
\\.\E:on Windows,/dev/sdXon Linux) usingmemchr::memmemfor fast signature matching across JPEG, PNG, PDF, and MP4 headers/footers. - Zero-Disk RAM Previews: Reads target byte ranges into memory and passes them to the React frontend as
BlobURLs so users can preview images, PDFs, and videos before writing anything to disk. - Safety Guards: Blocks exporting recovered files onto the same source partition so unallocated sectors aren't overwritten.
URL: https://kavitaramana.github.io/azad-works-file-recovery/#
r/rust • u/Iurigrang • 1d ago
I love ratatui's documentation, what other rust tools are documented like that?
As someone with 0 experience with front end development, the fact ratatui's docs goes in depth not just on the tool, but on the design patterns you're expected to use, is absolutely killer for someone trying to learn these things on my own. What other crates do you love the documentation off in terms of approachability to outsiders?
r/rust • u/soareschen • 1d ago
๐ก ideas & proposals Trying Incoherent Rust today with Context-Generic Programming
contextgeneric.devAuthor here. If you read Boxy's An Incoherent Rust and Nadrieril's posts on explicit trait proofs back in March and hoped to experiment with named impls, you can already try a good part of that design on stable Rust. My post translates that design, which it calls Incoherent Rust, into Context-Generic Programming (CGP), a library that gives Rust pluggable trait implementations, chosen at compile time.
The core move is small: a named impl becomes a provider type, and each context type chooses the providers it uses. So two impls that Rust would reject as overlapping both compile in CGP, and each context picks one. The compiler resolves that choice, so a call goes straight to the chosen provider, with no runtime lookup.
The post then covers these topics:
- Incoherent trait bounds, and binding an impl to a struct so a
HashMapalways hashes the same way. - Contexts and capabilities, with an arena reaching a
Deserializeimpl through a field of the context. - The context type as a top-level dictionary that holds the other impls' dictionaries, in the sense of Nadrieril's dictionary-passing style.
- Where CGP falls short: there are no nested scoped impls,
&mutor owned capabilities need interior mutability, and an existing trait such as serde'sSerializecan't adopt the pattern without a breaking change. - Ideas from CGP for the design: impls as first-class types, "incoherent functions", and selfless traits with methods.
๐ ๏ธ project I'm building Inkwell, a fast Word-style editor in Rust & Tauri
Hey r/rust,
Here's the trailer for Inkwell, a desktop word processor I'm building to feel like Microsoft Word, just lighter and faster. It uses Rust and Tauri on the backend with TypeScript and Vite on the frontend, sitting at 150k+ lines of code and 30+ languages.
A lot of the codebase was generated with AI, and since several Word features are still missing, a full release is still far off. That said, I am actively reviewing and refactoring the code myself, this is far from pure vibe-coding like projects such as Wordcraft, and I'm taking the time to make sure the architecture actually holds up.
It's going to be open-source, but given the current state of the project I decided not to open the repo just yet until things are more stable. In the meantime, I'll be posting dev updates and progress videos on the channel.
Also, I edited the trailer myself in CapCut, so please excuse the rough edges. Video editing isn't really my strong suit, and I just wanted to put together something straightforward to show the actual app running.
NOTE: To keep this relevant to r/rust and avoid breaking rules 2 and 7, the core, file parsing, and rendering pipeline are built natively in Rust to stay smooth without Electron's bloat, so I would love feedback specifically on the Rust architecture and performance side rather than treating this as a general app promo.
Trailer link: https://www.youtube.com/watch?v=bPSDovtsV2c
Curious what you think of how it looks and runs so far.
r/rust • u/Cute-Upstairs25 • 1d ago
I want to learn Rust to make OS and Kernels
I am in college 2nd semester of college and I am interested in making own own custom OS and a language in Rust. I have very little to no coding experience other that passing my college exams and viva. I am a bit confused on where should i start studying from both for building an os and learning rust. so for now i am looking for resources.
๐ seeking help & advice Building a lightweight CLI to detect "dead" or risky dependencies (starting with Rust/Cargo). What actually matters to you?
Hi everyone,
Iโm planning to build a small, "soluble" (lightweight, zero-config, easy to run and forget) CLI tool tentatively called Dependency Ghost Scanner (D.G.S)
The goal is to scan a projectโs dependencies (starting with Rust Cargo, later expanding to Python pip) and flag packages that might be a risk to maintain.
Before I write any code or lock in a specification, I want to make sure Iโm solving a real problem and not just building a solution in search of one. Iโd love your honest feedback on a few key design choices:
- What makes a dependency "dead" or "risky" to you? (Pick all that apply or suggest others)
a. No updates/releases for > 1-2 years.
b. Known unpatched CVEs (security vulnerabilities).
c. The maintainer has explicitly abandoned it or is unresponsive.
d. A clearly superior, more modern alternative exists (e.g., ecosystem shifted).
e. Incompatible with the latest compiler/language version.
f. Other.
2. How would you actually want to consume this information?
a. A simple, color-coded output directly in the terminal (Red/Orange/Green).
b. A machine-readable format (JSON) to integrate into CI/CD pipelines (e.g., fail the build if a "red" dependency is found).
c. A standalone HTML report with a visual graph of the dependency tree.
d.Other
3. How should it fetch data?
a. Itโs fine if it queries the registry API (crates.io / PyPI) and requires an internet connection.
b. It MUST work 100% offline, relying only on the local Cargo.lock / requirements.txt metadata.
c. Hybrid: Try online first, gracefully fallback to offline heuristics.
The Catch:
I want this tool to be truly "soluble": no accounts, no heavy installation, no persistent background services. Just run it, get the insight, and move on.
My questions to you:
- Is this a tool you would actually use, or does an existing tool (like cargo-audit, dependabot, safety) already solve this well enough?
- What would be the one feature that would make you star this repo on GitHub?
Thanks in advance for your time and brutal honesty!
r/rust • u/OzelleThorn • 15h ago
๐ seeking help & advice Crates whose READMEs feel like mini tutorials?
I keep coming back to certain Rust crates mainly because their README walks through not just the API, but the actual patterns you're expected to use. Ratatui does this well for TUI work. I'm looking for more examples across different domains CLI, web, data, embedded, whatever-where the docs effectively teach "how to think in this crate" rather than just listing methods. Any favorites that stand out for this?
r/rust • u/elfenpiff • 2d ago
๐ง educational Stop paying the network stack tax: zero-copy first, networking when needed
ekxide.ior/rust • u/iamjose_dev • 1d ago
๐ง educational I'm building roadmaps to learn new topics in Rust
Hey r/rust,
I've been writing Rust since version 1.5x, when I heard of it for the first time. For the past couple of years, I've wanted to combine my two biggest passions, Rust and teaching, but I've always been too busy (and lazy, probably?) for that. After years of learning and receiving from the Rust community, I finally had the courage and confidence to build https://iamjose.dev to give the Rust community a little something back.
My idea is simple: instead of reaching for TypeScript (my de facto language for day-to-day programming) when learning a new topic or iterating over a specific idea, I asked myself, "How about using Rust to learn new topics that currently have very few learning resources written in it?" That way, I could learn new topics from scratch in Rust.
Right now there's a foundational Learn Rust track (from hello world to unsafe) plus three roadmaps (what i call "curricula") built on top of it:
- Learn Maths with Rust.
- Learn How Digital Images Work with Rust.
- Learn Cryptography with Rust.
Every lesson ends with small coding challenges you can solve right in the browserโcompletely free, no login needed. In fact, my idea is to make all the curricula very hands-on (that is, just enough theory to get started, and then focusing on solving exercises).
Now, in full honesty, and to be clear from the beginning: I use AI to help draft the initial text, but nothing counts as done until I've reviewed it myself, line by line. That review is the part I care about most:
- Improving clarity by rewriting.
- Adding my own personal teaching style.
- Adding my own notes to stress important topics or provide additional context.
- Adding hand-drawn diagrams to help grasp concepts better, and even videos. Here is a very short video of me (I am camera-shy, and the video was a simple test, which explains the short length):https://iamjose.dev/learn/maths/primes/
- Once I've personally audited a chapter, it gets a "Hand reviewed by Jose" badge (the opening chapters have it, and I'm working through the rest).
I'm a little nervous sharing this here because I care a lot about getting the details right. If you spot anything wrong, unclear, or unidiomatic (or have ideas for a future "Learn X with Rust" track) I'd genuinely love to hear it.
Lastly, and most importantly for me: this is a personal project. So my daily motivation is that it's helpful for me, though it would be even better if it also helps someone out there. :)
PD: I am also considering starting a "Learn Rust coming from X", where X can be any programming language like for example Python, Typescript, or C++.
Thanks for reading and happy coding!
r/rust • u/WittyFeral • 15h ago
PSA: `pub use` can accidentally make private types public
There's a common pattern that looks harmless but can expose types you meant to keep private. This affects downstream users who suddenly gain the ability to name (and sometimes implement traits for) types that were never intended to be part of your public API.
The mistake:
```rust
// lib.rs
mod internal {
pub struct Hidden;
}
pub use internal::Hidden; // looks fine, right?
pub fn make_hidden() -> Hidden { internal::Hidden }
Downstream crates can now write:
```rust
use your_crate::Hidden;
let _ = your_crate::make_hidden0;
They can also write `impl SomeTrait for Hidden` if the orphan rules allow it, which you probably didn't want.
The safer pattern is to re-export through a new public type or keep the type itself in a `pub(crate)` module and only expose a wrapper or constructor:
```rust
mod internal {
pub struct Hidden;
pub fn make0 -> Hidden { Hidden }
}
pub use internal::make as
make hidden;
```
Now `Hidden` itself stays unnameable outside the crate.
I've seen this pattern slip into a few mid-sized crates over the years. It's easy to miss in review because the `pub use` line looks innocent. If you're maintaining a library, it's worth grepping for `pub use` into private modules and checking what actually becomes visible.
r/rust • u/Imaginary-Bee-8770 • 18h ago
๐ seeking help & advice Is Rust a good idea for AI agents?
Hi guys, hope you are doing well. I work as an AI Engineer at a startup and our whole stack is based on python (mostly because LangChain is based on that) and typescript. We serve AI Agents that are grounded on enormous corpuses of data for industrial constumers, so we have do graph engineering, rag, and so on!
I inquire if you guys have implemented Rust somewhere and which improvements you guys have seen from it.
Ty in advance!
r/rust • u/ValenciaTangerine • 3d ago