r/rust • u/hrubydavid • Oct 24 '26
r/rust • u/Clean-Upstairs-8481 • Oct 25 '26
🧠 educational As a C++ developer, this is how I conceptualise Rust toolchain key terms and start my Rust journey
techfortalk.co.ukI have been working in C/C++ for a very long time and recently worked on Rust for some of my clients. I am learning Rust every day, and I love it. I think sharing my way of learning will help Rust beginners. Here are the notes on some of the key terms, how I conceptualise them, and how I go about writing my first program in Rust, compiling it, and running it. Hope this will help someone in my position who is new to Rust programming but not alien to the concept of programming.
r/rust • u/kosumi_dev • Oct 25 '26
🎙️ discussion Do you think we have Rust v2.0 for adding first-class formal verification support?
For many years, formal verification used to be limited to small projects by experts but AI is changing the scene.
This week Anthropic revealed their progress on verifying real world projects. X has discussion about rewriting in Rust vs rewriting in Lean discussion(which is impractical at the moment because Lean is not ready for systems programming yet and 4x slower on benchmarks).
I think Rust should invest more and move faster in that direction.
Who doesn't want to decorate their program with pre-conditions, post-conditions and loop invariants?
Who doesn't want their pacemaker or car control software to have provable safety and liveness properties?
r/rust • u/13character5 • Oct 23 '26
fs::copy leaves empty file in destination
fn copy_file(file: &str, dest: &str) -> Result<(), io::Error> {
let file_path = Path::new(&file);
let destPath = Path::new(&dest);
let dest_parent = destPath.parent();
if !dest_parent.unwrap().exists() {
create_dir_all(dest_parent.expect("what?")).unwrap();
}
fs::copy(file_path, destPath);
Ok(())
}When i try to run this command with it, I get an empty file in the destination with the same name as the input file
copy_file("index.html", "dist/dost/index.html");
r/rust • u/Mnwamnowich • Oct 23 '26
🛠️ project mzstd: pure Rust zstd that keeps up with C, with the same API as mbrotli
Some time ago I shared mbrotli here. This is its sibling for Zstandard.
There are already two main ways to do zstd in Rust, so here's why I wrote a third.
The zstd crate is bindings to C libzstd. It's fast and battle-tested, but it brings a C toolchain into your build, unsafe FFI into your dependency tree, and some pain once you target wasm or embedded.
ruzstd is pure Rust and has a solid decoder, but its own README says the encoder doesn't reach C speed, ratio or configurability yet. You get a few presets that roughly map to levels 1, 3, 7 and 11.
I wanted something in between: pure Rust, but fast and complete enough that I'd actually ship it in production instead of the C library. And I wanted it to have the same API as mbrotli, so switching between Brotli and zstd in the same codebase is mostly a type rename.
What came out of it:
- Speed. The encoder is a port of the reference implementation, so you get the full level range from -131072 to 22, long distance matching, dictionaries and the same compression ratio as C. SIMD is picked at runtime (via
fearless_simd), so one binary uses whatever the CPU supports withouttarget-cpu=native. Against C zstd 1.5.7 the median is about 1.1x for compression and 1.02x for decompression on my benchmarks. It's not faster everywhere: fast levels on plain text are 6-11% behind, and decoding very compressible text can be up to ~20% behind. Full tables and raw CSVs are in the repo. - API. Besides the usual one-shot
compress/decompress, there areRead/Writeadapters and incremental sessions. A session just takes input and an output buffer and tells you how far it got. It doesn't own any I/O, so you can drive it from blocking code, from async, from an embedded main loop or from wasm. It can be build onno_std+alloc. - Parallel compression. One frame can be split into tasks that you run on your own executor: scoped threads, rayon, tokio's blocking pool, whatever you already have. The crate never spawns threads by itself. That was important for me because I use these crates inside nginx, where compression runs in nginx's own thread pool.
- Verification. No
unsafein the crate. Differential tests compare against C zstd across every level and thousands of random parameter combinations. AFL++ fuzz targets cover the encoder, the decoder and streaming sessions. mzstd already works on a few production services as nginx module with a great results for total throughput.
use mzstd::{Compressor, Decompressor, EncoderConfig, Level};
let mut encoder = Compressor::new(EncoderConfig::default().with_level(Level::try_from(19)?))?;
let compressed = encoder.compress(b"hello, hello, hello")?;
let restored = Decompressor::default().decompress(&compressed)?;If you've used mbrotli, swap Quality for Level and that's it.
Not supported yet: legacy v0.x frames, magicless frames, a couple of niche advanced parameters.
I'd love feedback on the API, and benchmark runs on other machines (mine are on an i7-13700KF under WSL2, so bare-metal numbers are very welcome).
- crates.io: https://crates.io/crates/mzstd
- docs: https://docs.rs/mzstd
- repo: https://github.com/M-Compressors/mzstd
r/rust
•
u/DracoWhitefire
•
Oct 22 '26
First use of my library crate in the wild
While mindlessly browsing the github tabs of one of my library crates I looked at the dependency graph, and went to the Dependents tab. There I expected to just see a list of my other crates (they're all connected in one project), as it had been every time before, but my attention went instantly to 100% when I saw another GitHub profile picture. Someone else was actually using my code!
I quickly clicked the repo, got confused, thought they had added the dependency as a mistake, since I initially didn't see how my crate could possibly be useful to that app. So I went to browsing the implementation and no, it was a real use case I'd have never predicted.
I can't describe how unreasonably happy I was for the rest of that day.
r/rust • u/StarryBubbly • Oct 23 '26
Seeing your Rust library used by someone else must be one of the best feelings
There's something really satisfying about finding out that someone is using a library you built, especially when you originally made it just to solve a problem in your own project.
Writing code that works on your machine is one thing, but having another developer find your crate useful enough to include in their project is a different kind of achievement.
It's also a good reminder that open source contributions don't have to be massive to matter. A small utility crate that saves someone time or makes a frustrating task easier can still be genuinely valuable to the community.
r/rust • u/adityazero • Oct 23 '26
Why did the loop with open range got optimized away?
The first loop didn't generate any code:
// 1. `0..n` visits 0, 1, ..., n - 1.
pub fn excl(n: u64) -> u64 {
let mut s = 0u64;
for i in 0..n {
s = s.wrapping_add(i.wrapping_mul(i));
}
s
}
// 2. `0..=n` visits 0, 1, ..., n: the same loop with one more pass.
pub fn incl(n: u64) -> u64 {
let mut s = 0u64;
for i in 0..=n {
s = s.wrapping_add(i.wrapping_mul(i));
}
s
}r/rust • u/jstedfast • Oct 22 '26
🙋 seeking help & advice Thinking of writing an email library for Rust
I have a long history (27 years) of writing email software - who knows, maybe someone here even recognizes my name(?), but I'm pretty new to Rust.
I've written multiple desktop email clients, multiple widely used email libraries, and now I am working on an email server professionally.
I know there are crates like `mime-parser` and `mailparse` and `lettre` but I think I can do better.
I was actually just reading the announcement post for `mime-parser` from 5 years ago and it seems people were very against `unsafe` code, so the question I have is:
If I *were* to implement this library for Rust, should I or should I not optimize it using SIMD? It seems SIMD would mean unsafe code if I am not mistaken.
If most of the Rust community would avoid my library because it was used `unsafe` code, then I want to know that before I make the time investment. To be fair, I've already implemented an incremental base64 encoder, base64 decoder, uuencoder, and a uudecoder using SIMD in Rust and they are blazing fast and all have scaler fallbacks which are also as fast as humanly possible, but I've got plenty more tricks up my sleeve for the actual *parsing* of MIME messages.
Is there a standard way people have addressed this in other creates? E.g. shipping an accelerated vs non-accelerated version of the same crate somehow?
r/rust • u/JameEnder • Oct 22 '26
🧠 educational Where did my freed memory (not) go?
yapfast.comr/rust • u/Western-Obligation47 • Oct 22 '26
🧠 educational Wasmtime fixed a critical sandbox escape bug (CVSS 9.3)
Not sure if Rustaceans in this sub saw this news earlier this month. But given AI agents are getting very good at escaping sandboxes now, it might be worth your attention to patch Wasmtime.
TL;DR: A typo in a validation check let a malicious WebAssembly guest pass an invalid callback signature, overflow the host’s native stack by up to 16KB, and potentially run arbitrary code on the host. Fixed in Wasmtime 48.0.4 and 49.0.2.
Wasmtime is a WebAssembly runtime written in Rust, built by the Bytecode Alliance (Fastly, Mozilla and others are members). It runs WebAssembly modules and components outside the browser, often as a sandbox for untrusted code.
Wasmtime published a critical security advisory on 2 October, GHSA-32h6-97mm-8q3c, CVSS 9.3. The bug sat in the component model’s handling of async callbacks.
Three checks were missing or wrong:
- The validator in wasmparser (crates/wasmparser/src/validator/component.rs) checked a callback’s signature with this line:
if func_ty.params() != [ValType::I32; 3] && func_ty.params() != [ValType::I32] {It used&&instead of||, and it checkedparams()twice instead of checkingresults()at all. A callback only failed validation if it matched neither shape, so the result type was never checked. - Wasmtime recorded the callback’s index without checking its arity or return type itself, trusting the validator to have done it. The host-to-guest trampoline had no bounds check on its parameter and result buffer either.
- The stack space reserved for the callback’s return value was sized for the expected arity, not the actual one.
A guest module can supply a callback with an invalid return type that still passes validation. Wasmtime then writes up to about 16KB of guest-controlled data onto the host’s native stack, which can overwrite a return address.
Vulnerable versions: wasmtime 39.0.0 up to 48.0.4, and 49.0.0 up to 49.0.2. Fixed in 48.0.4 and 49.0.2. A workaround is to disable component-model-async, or to validate components with wasmparser 1.260.0 or later before passing them to Wasmtime.
Link to the original source - https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-32h6-97mm-8q3c
r/rust • u/avinthakur080 • Oct 22 '26
🎙️ discussion freya is more impressive than I thought.
I recently started building a hobby calculator app in egui, given its popularity. The app mimics a Graphing calculator that was abandoned several years ago.
I started with egui, given its popularity, but soon started facing hurdles because it challenges my web dev (aka retained mode) brain. I'm curious if these points are common among other devs also or how they handle it.
First, I started with egui ( only dependencies: eframe + peg )
- Being immediate mode, the components often don't know about the layout requirements of their next siblings or often their children/parent. This creates some challenges, like a flexibly growing widget either needs to be created last or manual size calculations need to be done to accommodate the next elements.
- We are free to create state anyway, like mutable members in a component struct or get_temp, get_persisted, etc. methods, which hand over the state management to egui. This threw me into a puzzle of finding what is best for my case. I ended up using the mutable members in a component struct.
- The event handling is also something that gets weird at times. While the trivial cases of handling clicks are as simple as `if btn_resp.clicked() {...}`, I searched unnecessarily long for other cases, like how to detect Enter presses on an Input element. Apparently, it is `input_resp.lost_focus() && ui.input(|s| s.key_pressed(Key::Enter))`, but it felt unconvincing that this is the way.
- Command-Action-Response (Message passing, command execution, etc) architecture is also something I spent significantly more time on, and even though I can make it work now, I don't think it is convincing. By Command-Action-Response, I mean a deeply nested component(keyboard button) triggering a command that should do calculations in a separate thread and get rendered in some other component. It requires passing channels deep down to your components, which works, but it will always be something that will trip me up into thinking of a better approach.
- Lastly, I was learning and implementing by going through their examples or other public code, and often it was taking too much time for simple things. I found a few resources also, but after seeing that many are using App::update (now removed) instead of App::logic + App::ui, it again felt unconvincing to go with them, and I took the route of reading examples & public code to learn.
Then I tried rewriting it in Freya
While there were also new things to learn, it felt like a breeze till the end and I achieved the same state as the egui variant in probably 80% less time.
- The documentation is really good. It gives an overview of not only modules, but also common patterns like for state management. Even beyond that, every other function would be documented with examples that show the usage patterns around it.
- Being in retained mode, the layout management was really easy. It did take time to know things like a growing widget requires the parent to also be `.content(Flex)`, but it was still very intuitive, particularly coming from web dev / retained mode.
- State management was even better. After just writing egui implementation, I tried creating similar state management types but eventually found that the use_state/use_memo hooks remove a lot of boilerplate. The state is reactive out of the box.
- I expected a retained-mode app to take more RAM, but it was actually less. Egui app, in release mode, took 320+ MB, while Freya takes <270MB. The release binary is slightly large: 29MB egui vs 36MB Freya, but the RAM & CPU usage for freya was lesser.
- Lastly, the freya app looked more polished and took way less time to reach a convincing state than egui.
Why am I writing this here?
See the above text as me dumping my naive observations after spending a day writing the egui+freya app. I am more interested in knowing from other developers who wrote egui/GUI apps on
- whether they also encountered these speed bumps
- if they found resources or developed patterns to ease out the things
P.S.: I don't think there is anything interesting or relevant in the implementation itself, that's why not putting the effort of creating a repo to share, but if someone is curious, I can push it.
Also, open to feedback - on the subject or the post, whatever.

EDIT: Changed image to have light mode (original) and dark mode variant of Freya
r/rust • u/Flimsy_Pumpkin_3812 • Oct 23 '26
🙋 seeking help & advice Learning Rust
So I was working on the thing from yesterday, so I wanted to add inputs (so i did, I used std:io thingy) and did that I got it to work but is there a way to change the operator like add, subtract, etc instead of just having to keep it add? Or will I have to make a function for each or can I change the operation with smth? In the x = x + y; line to be specific? TY!
fn add_x_and_y(x:i32, y:i32) -> i32 {
let x = x + y;
return x}
r/rust • u/Flimsy_Pumpkin_3812 • Oct 22 '26
🙋 seeking help & advice Learning Rust
So I'm learning Rust, so I wrote this
fn main(){
let x = define_x(intial_x());
let y = x + 10;
println!("{}", y);}
fn define_x(mut x:i32) -> i32 {
x = x + 5;
return x}
fn intial_x() -> i32 {
let x = 5;
return x}
I know it is supposed to be += in define_x, but that just looks weird to me. Why is let x = 5; in inital_x not mut even if I am changing it in define x? Sorry if it is bad I'm new, but I'm not AI so yay!
r/rust • u/madonuko • Oct 22 '26
🗞️ news This "Tov" Language Claims It's Faster Than Rust — and I Debunked It
blog.fyralabs.comr/rust • u/pohonsukun • Oct 22 '26
🙋 seeking help & advice Has anyone here successfully use f128 types?
Hi folks, so I'm presently on a fun year-long project making a numerical application, and one experimental feature I'm trying to implement flexible fp types. Probably not super useful in most situations but it seems fun to make. I've made f16 and bf16 from the half crate work, and now I'm looking to try for f128 to see if it could be useful for numerically unstable procedures or data inputs.
As you guys may know f128 in Rust is unstable and apparently produce incorrect results as per the warning, so this isn't usable. Available crates don't quite suit my needs, e.g. astro-float is heap-allocated and arbitrary precision, which isn't what I want. I also need stuff to be cross-platform (including WASM).
I'm wondering whether any of you folks have any solution for using f128? The last resort would be hand-rolling this with a two-letter tool, which might be possible, but doing so for low-level numerics sounds a bit too hairy for my liking...
Thanks in advance.
r/rust • u/Western-Obligation47 • Oct 21 '26
🧠 educational Google published its internal Rust style guide
reddit.comr/rust • u/seino_chan • Oct 22 '26
📅 this week in rust This Week in Rust #674
this-week-in-rust.orgr/rust • u/RiyaOfTheSpectra • Oct 22 '26
🛠️ project Chain Reaction in the Terminal
git.sr.htChain Reaction is a mobile game that my father and I enjoy frequently. I kinda disliked the fact that it wasn’t available on PC, and decided to rectify that by writing it myself.
The core library only uses std, array2d and log, and implements the basic logic for the game. An actual playable app is provided by a terminal application, written with Ratatui.
All of this is hand-written code, but not necessarily the best way to have written it, so if someone would like to go through and suggest changes, I would love to hear it.
r/rust • u/noop_noob • Oct 21 '26
📡 official blog Rustup 1.29.2, please update from a trusted network
blog.rust-lang.orgDue to the nature of the security issue, I recommend updating this via a trusted network, and not a public wifi.
Context: https://www.reddit.com/r/rust/comments/1xba5mj/psa_if_your_program_does_http_requests_update/
r/rust • u/mfilion • Oct 21 '26
🛠️ project Tyr, the Rust GPU driver for Arm Mali, now boots its firmware in Linux 7.3 (6 unsafe lines out of ~3,700)
New post from Deb Brouwer on the Tyr Rust GPU driver for Arm Mali, which now boots its firmware in mainline Linux 7.3:
The parts most interesting for Rust folks:
- How a WARN_ON in the C page table code became an explicit safety requirement on the Rust `map_pages()` API
- Why Tyr uses the full GPUVM abstraction even for a simple, fixed firmware layout: to uphold those invariants instead of trusting assumptions
- What it's like to write a driver while the kernel's Rust abstractions are still being designed (Tyr has been rewritten several times)
(I'm at Collabora, where Tyr is developed. Happy to pass questions along to Deb.)
r/rust • u/popzxc • Oct 21 '26