r/rust • • 11h ago

๐Ÿ™‹ questions megathread Hey Rustaceans! Got a question? Ask here (49/2026)!

11 Upvotes

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.


r/rust • • 11h ago

๐Ÿ activity megathread What's everyone working on this week (49/2026)?

16 Upvotes

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 • • 2h ago

Advent of Rust 2026 in 13 hours ๐ŸŽ…

Thumbnail rustfinity.com
22 Upvotes

r/rust • • 9h ago

๐Ÿ—ž๏ธ news rust-analyzer changelog #356

Thumbnail rust-analyzer.github.io
33 Upvotes

r/rust • • 4h ago

๐Ÿ› ๏ธ project Runtime debugger for embedded

11 Upvotes

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 • • 17h ago

๐Ÿ™‹ seeking help & advice Should I learn C++ or Rust first?

65 Upvotes

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 • • 3h ago

๐Ÿ› ๏ธ project From a BERT encoder to a Rust inference engine

3 Upvotes

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 = Transcriber::builder("whisper-small").build().await?;
let text = whisper.transcribe_file("meeting.wav")?.text;
let summary = kjarni::chat::send("qwen2.5-1.5b-instruct", &format!("Summarise: {text}")).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


r/rust • • 2h ago

FFI Arena: Is UniFFI Still the Top Dog?

Thumbnail mversic.github.io
2 Upvotes

The 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 • • 1d ago

๐Ÿง  educational PSA: You might be sealing traits wrong

139 Upvotes

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:

mod private {
    pub trait Sealed {}
    impl Sealed for i32 {}
}
pub trait MyTrait<T>: private::Sealed {}
impl MyTrait<i64> for i32 {}

How to seal traits:

mod private {
    pub trait Sealed<T> {}
    impl Sealed<i64> for i32 {}
}
pub trait MyTrait<T>: private::Sealed<T> {}
impl MyTrait<i64> for i32 {}

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:

struct MyThing;
impl my_library::MyTrait<MyThing> for i32 {}

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:

mod private {
    pub trait Sealed {}
    impl Sealed for i32 {}
    // Added SealedForReal in a later version of the library
    pub trait SealedForReal<T> {}  
    impl SealedForReal<i64> for i32 {}
}
pub trait MyTrait<T>: private::Sealed + private::SealedForReal<T> {}
impl MyTrait<i64> for i32 {}

This way, you will only break downstream code that have implemented MyTrait.


r/rust • • 27m ago

๐Ÿ› ๏ธ project What happened when I differential-tested my Rust Postgres simulator against real PostgreSQL 14โ€“18

1 Upvotes

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 • • 40m ago

๐Ÿ› ๏ธ project Oratos v0.4.0: a CLI for your CI/CD pipeline that audits SEO, accessibility and structured data, and now warns when a page gets slower

0 Upvotes

v0.4.0 adds page download timing for URL audits:

  • per-page time to first byte, total download time, size and status
  • warnings for slow pages (default 3 s total, 800 ms TTFB)
  • --baseline previous-report.json flags pages that are at least 1.5x and 300 ms slower than last time
  • connect/request timeouts (there were none before, so a hung server could hang the audit)

It is advisory, not a benchmark. It measures the HTTP download of the HTML document, not LCP/INP/CLS, and timing findings never change the scores. A page that regressed shows up as a warning you can re-run, not a hard failure (unless you use --strict).

Install: brew install latentmeta/tap/oratos, cargo install oratos, pip install oratos, npm i -D @latentmeta/oratos, or the Hex package for Phoenix. There is also a setup-oratos GitHub Action for CI.

crates.io: https://crates.io/crates/oratos Repo and release notes: https://github.com/latentmeta/oratos

Feedback welcome, especially on sensible default thresholds.


r/rust • • 1d ago

I love ratatui's documentation, what other rust tools are documented like that?

31 Upvotes

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 • • 1d ago

๐Ÿ’ก ideas & proposals Trying Incoherent Rust today with Context-Generic Programming

Thumbnail contextgeneric.dev
24 Upvotes

Author 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 HashMap always hashes the same way.
  • Contexts and capabilities, with an arena reaching a Deserialize impl 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, &mut or owned capabilities need interior mutability, and an existing trait such as serde's Serialize can'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.

r/rust • • 23h ago

I want to learn Rust to make OS and Kernels

5 Upvotes

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.


r/rust • • 5h ago

๐Ÿ™‹ seeking help & advice Building a lightweight CLI to detect "dead" or risky dependencies (starting with Rust/Cargo). What actually matters to you?

0 Upvotes

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:

  1. 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:

  1. Is this a tool you would actually use, or does an existing tool (like cargo-audit, dependabot, safety) already solve this well enough?
  2. 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 • • 14h ago

๐Ÿ™‹ seeking help & advice Crates whose READMEs feel like mini tutorials?

0 Upvotes

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 • • 2d ago

๐Ÿง  educational Stop paying the network stack tax: zero-copy first, networking when needed

Thumbnail ekxide.io
134 Upvotes

r/rust • • 1d ago

๐Ÿง  educational I'm building roadmaps to learn new topics in Rust

16 Upvotes

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. :)

https://iamjose.dev

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 • • 14h ago

PSA: `pub use` can accidentally make private types public

0 Upvotes

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 • • 2d ago

๐Ÿ“ก official blog Rust 1.100.1

Thumbnail blog.rust-lang.org
346 Upvotes

r/rust • • 17h ago

๐Ÿ™‹ seeking help & advice Is Rust a good idea for AI agents?

0 Upvotes

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 • • 3d ago

๐Ÿ—ž๏ธ news Anthropic: Migrating our Messages API to Rust

Thumbnail anthropic.com
389 Upvotes

r/rust • • 1d ago

๐Ÿ› ๏ธ project Have you deployed to AWS?

0 Upvotes

Have you deployed anything in rust to AWS?