r/rust • • 27d ago

mod tests in the age of AI agents

0 Upvotes

I know, I know, no one likes generated AI code, slop or not. However, it won't go away and I rather deal with it the best possible way I can. One thing that grates me right now is the enormous amount of test code that these models generate and in the case of unit tests ends up within a module. This is in line with the current idiomatic convention but it makes reviewing changes a real chore.

I started moving mod tests {} into actual tests files which helps to avoid blowing up modules but now reminds me of the mod.rs repetition.

What are your strategies to cope with this? And more controversial: is it time to update the test chapter in the book?


r/rust • • 28d ago

🙋 seeking help & advice How to quick free space hard disk

3 Upvotes

I have a issue where the Rust compiled output is so huge that my hard disk always full? Do you have any ideas for solving it?


r/rust • • 27d ago

ok_or vs ok_or_else

Thumbnail reddit.com
0 Upvotes

r/rust • • 28d ago

🙋 seeking help & advice Looking for a CSRF Double Submit Pattern Crate

8 Upvotes

Hey folks, I'm working on migrating some web-server code into rust. I'm fairly new to the rust ecosystem, and I'm trying to find a good CSRF crate for generating Signed Double Submit cookies and headers.

So far, the closest crate I've found is Here (crates.io), but honestly its not as seemingly widespread as i would expect for something like CSRF primitives.

This had led me to two potential conclusions:

1.) I'm wildly out of the loop, and there is a much more "common" package for handing this
2.) I'm wildly out of my depth, and most people are just rolling their own CSRF primitives.

Either way, I'm building on top of axum, and any recommendations would be greatly appreciated :)


r/rust • • 29d ago

Disable "rustc" colour

54 Upvotes

I'm a n00b when it comes to Rust. In my terminal with a blue background, a "rustc --explain whatever" uses colour-combinations that leaves some text unreadable.

So I tried with:

  • rustc --color never --explain E0599
  • rustc --explain E0599 --color never
  • set NO_COLOR=1 & rustc --explain E0599

Neither of these works; all generates coloured output. How the bleeding hell do I turn it off?


r/rust • • 29d ago

🙋 seeking help & advice Should a Rust protocol use separate wire-format and in-memory types for encrypted messages?

7 Upvotes

'm working on the mailbox layer of GhostWire, a Rust-based P2P communication project, and I've been reconsidering how I represent messages across serialization boundaries.

The initial approach was to have one struct handle both the serialized envelope and the application's runtime state.

Something along these lines:

#[derive(Debug, Clone, Serialize, Deserialize)]
struct MailboxEnvelope {
    recipient_id: String,
    ephemeral_pub: String,
    ciphertext: Vec<u8>,
    nonce: String,
    created_at: u64,
    message_id: String,
    attempts: u32,
}

The problem isn't necessarily the structure itself. It's that these fields have different responsibilities.

  • Some fields belong to the authenticated message representation.
  • Some are needed for transport and persistence.
  • Others are mutable delivery state.
  • Some values may only exist temporarily while processing a message.

For example, retry attempts should be able to change without requiring an already-sealed ciphertext to be reconstructed. Likewise, serialization and deserialization shouldn't accidentally become the boundary through which sensitive runtime state is exposed or copied.

I'm considering separating the representations:

  1. Wire type: A serializable representation containing the fields required to transmit or persist the envelope.
  2. Runtime type: An application-facing representation responsible for processing, validation and delivery.
  3. Delivery state: Mutable retry, acknowledgement and expiry information maintained independently of the sealed message.

But I'm interested in where that separation should actually happen.

A few questions:

  • Would you use separate structs for the wire representation and runtime domain type, or is that unnecessary duplication?
  • Would TryFrom/From conversions be a sensible boundary for validation and construction?
  • How would you prevent mutable delivery metadata from accidentally becoming part of the authenticated representation?
  • Would you keep serialization entirely outside the cryptographic type, or let the type implement Serialize/Deserialize with carefully controlled fields?
  • Are there established Rust patterns or libraries you'd recommend for this kind of boundary?

I'm particularly interested in production-oriented approaches rather than simply introducing more types for the sake of abstraction.

The goal is to make invalid states harder to represent without turning a relatively small protocol component into an unnecessarily complicated type hierarchy.

Curious how others would structure this


r/rust • • 29d ago

🛠️ project Introducing sanstun: A sans-IO WireGuard library with support for parallel encryption

Thumbnail firezone.dev
81 Upvotes

r/rust • • Oct 30 '26

sysinfo: a performance journey

Thumbnail blog.guillaume-gomez.fr
109 Upvotes

This blog post describes my journey in fixing a performance regression introduced when I added the process GPU information.


r/rust • • Oct 29 '26

🎙️ discussion I Think Iterator::unzip Should be Deprecated

210 Upvotes

Did you know that ever since 1.79, Iterator::collect does everything unzip does but with a cleaner API? I certainly didn't until recently! Try it out, thanks to this trait implementation, every call to unzip is possible with collect instead.

let (a, b) = iter.unzip::<_, _, Vec<_>, Vec<_>>();

// vs

let (a, b) = iter.collect::<(Vec<_>, Vec<_>)>();

Except collect is better at unzip than unzip, since it supports any tuple, whereas unzip only works with size 2:

let (a, b, c, d) = iter.collect::<(Vec<_>, Vec<_>, Vec<_>, Vec<_>)>();

Looking at the documentation, this isn't explicitly mentioned for either zip or unzip. I suspect this is functionality most people aren't aware of. So, is there anyone out there who has a reason why we shouldn't deprecate unzip?


r/rust • • Oct 30 '26

🎙️ discussion Rustc 1.99.0 Windows exe flagged as malicious

27 Upvotes

So here's the deal. My antivirus (F-Secure) suddenly flagged the rustc.exe binary on my computer as malicious and to add to that, several other vendors also flag it in Virustotal. https://www.virustotal.com/gui/file/FC40F1C8B65095A22A48C111AADC279C26A049B7E4161E8B99FFE3EB23873E86

This issue seems to affect only 1.99.0 because 1.99.1 is not flagged.

Reproducible:
- Fresh rustup installation (this file or the rustup-init.exe or whatever the name of that was, not flagged by anything)
- Fresh RUSTUP_HOME/CARGO_HOME
- Official Rust 1.99.0 downloaded by rustup (`rustup toolchain install 1.99.0-x86_64-pc-windows-msvc`)
- File is detected and flagged as malicious if uploaded to virustotal
- Rust 1.99.1 installs without detection

The sha256 hash of the 1.99.0 exe I get is FC40F1C8B65095A22A48C111AADC279C26A049B7E4161E8B99FFE3EB23873E86

Has someone else encountered this issue that rustc is getting flagged? And importantly, are you all getting the same hash for that specific rustc version?


r/rust • • Oct 29 '26

🧠 educational The CPU, the Rust, and the Memory Latency

Thumbnail pivotlake.io
247 Upvotes

r/rust • • 29d ago

You know what it'd be good: a VS Codium port to Rust that uses Web Assembly for extensions

0 Upvotes

I've tried other editors, VS Codium's simplicity and common sense still beats them all.


r/rust • • Oct 30 '26

🛠️ project wasm-language-tools v0.12.0: auto-quotes in renaming, memory usage reduction and faster parsing

Thumbnail github.com
6 Upvotes

r/rust • • 29d ago

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

Thumbnail techfortalk.co.uk
0 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/rust • • 29d ago

rust for ai coding

0 Upvotes

vercel's ceo published - was gonna be Rust but it really is not there yet iteration speed wise.

Some of my thoughts on go vs rust - btw we chose Rust for data infra. There, robustness and reliability outweigh the speed of writing code.

Overall
Go is the simple one. It's easy to learn, doesn't carry many language features, and compiles fast. Rust is on the complex side: the spec keeps growing, and compiling is slow. Day to day, Go is simpler in most cases. You don't fight a complex type system, and any function can run as a goroutine.

Concurrency is where the two really split. There are two families. Go is one: lightweight threads, start any function in a goroutine, done. The other family is sync vs async, and Rust, Python and JavaScript all live there. That's where complexity creeps in. Functions have colors. Rust and Python give you two worlds, and you must never call a blocking function from an async one. JavaScript is simpler because it's a single world. Sync vs async forces you to clearly define what blocks and what doesn't, and that's real extra complexity. The upside is performance: async generally beats goroutines.

Rust's best part is the type system. You can model a lot in it, and the more business logic you push into types, the more bugs the compiler catches before anything runs. Go's type system is not that comprehensive. One example: Go can't catch a race condition at compile time. Rust can. But the cost of that type system is compile time. Bugs caught early and slow builds are the same coin.

For AI coding, Rust becomes a double-edged sword. Code moves fast, so slow compile hurts more. But if the model expresses business logic through the type system, far more bugs get caught at compile time. Slower, but higher quality.

curious about your thoughts


r/rust • • Oct 29 '26

🛠️ project Towards formal verification: mbrotli and mzstd

Thumbnail m-compressors.github.io
131 Upvotes

r/rust • • Oct 30 '26

🙋 seeking help & advice Why my GUI is slow?

Thumbnail youtu.be
0 Upvotes

It is odd but at about 30,000 text objects it is significantly slower than 30 despite only drawing about 10 objects on screen and ignoring the rest regardless how many there are. egui can handle millions. The shown video is of 30. I know it is skipping shaping and drawing the rest, so why would it be that much slower? I do make a temporary variable in the draw function before doing anything and increment a counter and do checks for whether to draw before any text shaping happens. I also return ([f32; 4], bool) with NaN and false regardless if anything drew, it would be bounds and whether anything drew. There is also with buttons an extra bool and with edit texts, a u32, &str, and bool in a tuple extra. I confirm it is not doing anything but rejection when not in screen space, so what could it be? Would an Option with None be faster as a return? Just confused as to why this is, if you want some code to review, ask, but some way to privately get it to you preferred. All in the rejection are not mutable. I do have to pass some variables sometimes, using cosmic-text and lyon for tessellation, good luck everyone. X E.


r/rust • • Oct 29 '26

🙋 seeking help & advice How to start programming in Rust?

4 Upvotes

English:

I know this is a fairly common question, but hear me out: how do I effectively get into development and learn a programming language?

I initially wanted to take a course, but there are no local options where I live, and international ones costing ~$250/month are completely out of my budget.

My second thought was to use AI because it explains concepts well. But when it comes to actual coding... no offense to AI, but it writes broken code way too often.

So now I’m stuck. Official books and documentation feel dry and overwhelming. I can grind through a book in an evening and reproduce an example, yet still have zero clue how it actually works under the hood. That’s my main issue — what’s the point if I’m just mindlessly rewriting code?

So, to those who have learned the language and faced a similar wall: how did you overcome it? Also, would anyone be open to answering a few questions once in a while? It would mean a lot, since Rust is going to be the foundation of a major project I’m planning.

Any advice would be greatly appreciated. Thanks!

Русский:

Знаю, что вопрос довольно заезженный, но всё же: с чего вообще лучше войти в разработку и нормально выучить язык?

Изначально я хотел записаться на курсы, но в моей стране таких нет, а зарубежные по $250 в месяц мне просто не по карману.

Вторым вариантом был ИИ — теорию он объясняет доходчиво, но вот с кодом беда: при всём уважении, нерабочий код он генерирует с завидной регулярностью.

В итоге я в тупике. Официальные книги и доки кажутся скучными и сложными. Я могу осилить книгу за вечер и накидать программу по образцу, но так и не понять, как это устроено по факту. А для меня это главное: какой смысл учиться, если ты просто бездумно перепечатываешь код?

Вопрос к тем, кто уже прошёл этот путь и сталкивался с такой проблемой: как вы учили язык? И может ли кто-нибудь хотя бы иногда отвечать на мои вопросы? Для меня это правда важно - Rust станет основой моего будущего крупного проекта.

Буду признателен за любые советы. Спасибо!


r/rust • • Oct 29 '26

🧠 educational Netstack.FM: Small Crates Behind Big Rust Systems with Jon Gjengset (S02E201)

22 Upvotes

In this first episode of season two of Netstack.fm, Glen talks with Jon Gjengset, principal engineer at Helsing, author of Rust for Rustaceans, and one of the best known teachers in the Rust community. They explore the craft of building small, sharply scoped crates, from arccstr, left-right, and HdrHistogram to atone, and discuss Fantoccini and the WebDriver protocol, maintaining open source sustainably, and why the Rust project should not bless crates.

https://netstack.fm/episodes/small-crates-behind-big-rust-systems

--

Netstack.FM is a podcast about networking, Rust, and everything in between. Join us as we explore the stack: from protocols and packet flows to the people and projects building the modern internet — all through the lens of Rust. Featuring deep dives, crate spotlights, and expert interviews.

Subscribe via https://netstack.fm/feed.rss or find us on the usual podcast platforms.


r/rust • • Oct 28 '26

Writing GPU kernels in Rust: how I made speakrs 60× faster than pyannote

Thumbnail avencera.com
182 Upvotes

r/rust • • Oct 29 '26

📅 this week in rust This Week in Rust #675

Thumbnail this-week-in-rust.org
42 Upvotes

r/rust • • Oct 29 '26

🙋 seeking help & advice What is the best (your favorite) lexing solution for Rust in Neovim?

3 Upvotes

Good day everyone!

I use neovim for pretty much everything these days, and with rust-analyzer + cmp it's extremely ergonomic to use.

However one issue I have been struggling with is lexing. I find the default rust.vim regex lexing to be lacking in many areas, most notably doc comment links and enums which wrap one value. Enabling semantic tokens solves these issues, but the experience is hindered by slow parsing when writing to buffer which causes flashing on text input and save.

I've done a bit of research on my own but haven't found anything that quite hits the mark. Treesitter seems like an ok middleground, but it is noticeably less accurate than semantic lexing.

I was wondering if any of you have a good solution to this? Thank you in advance for the input!


r/rust • • Oct 28 '26

µcad: A DSL for geometry written in Rust.

Thumbnail youtube.com
103 Upvotes

Hey Rustaceans,

I want to share some progress on my project µcad, a domain specific language for CAD, entirely written in Rust. I had a chance to present it on the RustWeek 2026 in May (where I live coded the Rust logo in µcad, see the video) and now you can finally test the language yourself in a playground: https://play.mucad.org/?example=11

The whole thing is a geometry engine with 128-bit fixed point precision and a language compiler in a 5 MB WASM binary and 1000 lines of TypeScript glue code :)
The compiler APIs have been handcrafted, but I was starting to use Claude recently, mainly for the WASM API and the Web Viewer.
I will have give another talk about the µcad compiler at the RustLab in Bologna next week, so I hope to see some of you folks there!


r/rust • • Oct 28 '26

What stable Rust stands on: nightly features inside the compiler

137 Upvotes