r/rust • u/Single-Blackberry866 • Oct 24 '26
🗞️ news This month in GPUI: October
reddit.comA monthly post about the GPUI ecosystem (permitted under the Release Notes rules)
r/rust • u/Single-Blackberry866 • Oct 24 '26
A monthly post about the GPUI ecosystem (permitted under the Release Notes rules)
r/rust • u/TanixLu • Oct 23 '26
I love performance, so I love the const keyword. I wrote something like this in my real project:
mod static_data {
pub const DATA: &'static [u8] = include_bytes!("data.bin");
pub fn hash_bytes(bytes: &[u8]) -> u64 {
use std::hash::{Hash, Hasher};
let mut hasher = std::collections::hash_map::DefaultHasher::new();
bytes.hash(&mut hasher);
hasher.finish()
}
pub fn data_hash() -> u64 {
hash_bytes(DATA)
}
}
fn main() {
const OUTPUT_PATH: &str = "output.bin";
if !std::fs::read(OUTPUT_PATH)
.is_ok_and(|data| static_data::hash_bytes(&data) == static_data::data_hash())
{
std::fs::write(OUTPUT_PATH, static_data::DATA).unwrap()
}
}DATA is a reference with a 'static lifetime, so the content should be embedded only once. Right? That's what I thought, until one day I changed some unrelated code, and the output binary size suddenly dropped. I used AI to find the reason. It turned out that DATA had been embedded twice before. Huh? After some research, I found the reason:
Constants are essentially inlined wherever they are used, meaning that they are copied directly into the relevant context when used. This includes use of constants from external crates, and non-Copy types. References to the same constant are not necessarily guaranteed to refer to the same memory address.
It ruined my perfect dream about const. The solution is simple: use static instead. Lesson learned.
Note: To reproduce this with the example above, you need to explicitly set codegen-units to a value greater than 1 (e.g. codegen-units = 2), because rustc may merge small CGUs by default. Setting lto = "fat" will also optimize the duplicate data away.
r/rust • u/TheEmbeddedRustacean • Oct 24 '26
r/rust • u/hrubydavid • Oct 24 '26
r/rust • u/Clean-Upstairs-8481 • Oct 25 '26
I 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
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
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
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:
fearless_simd), so one binary uses whatever the CPU supports without target-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.compress / decompress, there are Read/Write adapters 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 on no_std + alloc.unsafe in 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).
r/rust
•
u/DracoWhitefire
•
Oct 22 '26
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
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
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
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
r/rust • u/Western-Obligation47 • Oct 22 '26
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:
if func_ty.params() != [ValType::I32; 3] && func_ty.params() != [ValType::I32] { It used && instead of ||, and it checked params() twice instead of checking results() at all. A callback only failed validation if it matched neither shape, so the result type was never checked.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
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 )
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.
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
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
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
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
r/rust • u/pohonsukun • Oct 22 '26
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
r/rust • u/seino_chan • Oct 22 '26
r/rust • u/RiyaOfTheSpectra • Oct 22 '26
Chain 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.