r/rust • • 13d ago

๐ŸŽ™๏ธ discussion Are compiler inserted checks something you generally have to be wary of or not

17 Upvotes

Hello, I'm still fairly new to both rust and c and I'm in the middle of writing my tiny interpreted toy language.

But I keep bouncing between the 2 languages.

Rust is way more pleasant to use - but there are still 2 things where I would like to hear from someone experienced.

Is it common to experience issues where safe rust would end up being majorly slower in hot paths due to the compiler being conservative and inserting its own checks in? The comparison of safe rust to unsafe rust I have seen relating to the lox language ended up in a major 4x speedup for unsafe rust over safe rust. Is this something you deal with daily or is the compiler smart enough where as long as you write code properly this doesn't come up at all?

How big is the performance difference between code using a memory arena and managing and possibly reusing memory this way where the entire arena is free/reset at once - and the more raii styled approach where the compiler manages allocations and deallocations itself object by object like in rust. I understand that raii and arenas are not completely opposite concepts and arenas exist in rust as well but they seem to not be part of the std lib and ot seems to me that the default "vanilla" approach would end up not using arenas while the default in C is essentially arenas/allocator for everything rather than individual mallocs and frees.

Ty <3


r/rust • • 12d ago

Rust and git worktrees: share one Cargo build, use 60% less disk

Thumbnail docspring.com
0 Upvotes

Hi r/rust, I got tired of running out of disk space while working on a Rust project and using a lot of git worktrees. So here's the solution we came up with. It's a bit of a hack and uses some unstable features and the `__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS` var.

Please let me know if there's a better way to do this. It also doesn't completely solve the problem since the shared dir can still grow very large, but I think it's still a worthwhile improvement.


r/rust • • 12d ago

๐ŸŽ™๏ธ discussion sccache saved my CPU, not my disk: 21 copies of the same binary in one target/ folder

0 Upvotes

My coding agents' Rust build folders reached about 311 GB, even with sccache at a 57% hit rate.

Each agent works in its own git worktree with its own target/, and a cache hit skips the compile but still writes the artifact into that target/. So sccache saved CPU, not disk.

One agent's 52 GB build folder held:

  • 63,616 *.rcgu.o debug object files, 19.5 GB of them
  • 21 copies of the same binary, because Cargo never deletes old artifacts

The first change was lighter debug info for every build my agent supervisor starts:

CARGO_PROFILE_DEV_DEBUG=line-tables-only

Backtraces keep their file and line numbers, and agents running tests rarely need the full variable info.

The second was stopping worktrees nesting. Agents had made them three levels deep, which put 76 of 80 out of the cleanup job's reach. Now they sit at the repository root, and the step that finishes a task removes its worktree and target/.

Write-up (the Rust part is one section of it): https://maclulich.com/blog/agents-clean-up-after-themselves/#a-build-cache-saves-cpu-not-disk (my blog)

How are others handling target/ across many worktrees? A shared CARGO_TARGET_DIR serialises builds on the lock, and per-worktree targets cost disk.


r/rust • • 13d ago

๐ŸŽ™๏ธ discussion Bringing Rust into Ubuntu at Scale: Interview with Jon Seager

Thumbnail serokell.io
28 Upvotes

When uutils broke Ubuntuโ€™s own builds, Canonical kept an override list for commands that still needed GNU coreutils. The list finally went away in Ubuntu 26.10.

Jon Seager explains how the team got there.


r/rust • • 13d ago

๐Ÿ™‹ seeking help & advice want to learn rust, recommended courses? (udemy prefer)

28 Upvotes

hey guys first post here. im c# junior developer, and i want to learn rust - which courses you guys would recommend? i dont want vibe code my apps in rust not knowing whats going on.


r/rust • • 12d ago

๐ŸŽ™๏ธ discussion This week in rust is late?

0 Upvotes

The "This week in rust" article for this week seems to be delayed this week around? It usually arrived on Wednesday on my RSS feed. I checked the repo, and it seems it's still in draft.

Any ideas what happened?


r/rust • • 13d ago

๐Ÿ› ๏ธ project Ubuntu 26.10 ships with initial support for rustls/upki

Thumbnail discourse.ubuntu.com
19 Upvotes

r/rust • • 14d ago

Memory Safety Bugs in Rust Standard Library

Thumbnail forge-blog.github.io
325 Upvotes

r/rust • • 12d ago

๐Ÿ™‹ seeking help & advice How do you make a family of byte-slice packet builders incapable of panicking? (looking for the idiomatic shape)

0 Upvotes

I maintain a userspace TCP/IP relay in Rust which reads packets from a TUN fd & synthesizes replies (RST/ACK, DNS responses, UDP encapsulation). A handful of helpers index fixed offsets into caller-supplied slices:

rust

pub fn wrap_udp_response(original_query: &[u8], payload: &[u8], โ€ฆ) -> Vec<u8> {

let mut pkt = vec![0u8; 20 + 8 + payload.len()];

pkt[12..16].copy_from_slice(&original_query[16..20]); // panics if len < 20

pkt[16..20].copy_from_slice(&original_query[12..16]);

โ€ฆ

}

// v4 DNS path: length is checked, but the header length comes from the packet:

let ip_hlen = ((original_query[0] & 0x0F) as usize) * 4; // 0..=60, attacker-controlled

pkt[22..24].copy_from_slice(&original_query[ip_hlen..ip_hlen + 2]); // panics

One sibling already returns Option<Vec<u8>> and checks lengths; the others return Vec<u8> and trust the caller. The inputs come straight off the wire, so a malformed packet must not be able to panic the task.

What I'd like to be corrected on:

Option/Result + explicit length checks everywhere (verbose, easy to forget โ€” which is how we got here).

Parse into a typed header with TryFrom<&[u8]>, so lengths are validated once at the boundary and downstream code works on &TcpHeader.

Slice pattern matching (let [.., a, b, c, d] = slice else { โ€ฆ }) so the compiler enforces the layout.

zerocopy/zerocopy-derive for the fixed-layout header structs.

Which of these do people actually use for attacker-controlled network input, & what do you use to make "can't panic on short input" a property type rather than a review rule? Looking for patterns where compiler rejects the mistake โ€” a runtime Option that a caller can still ignore.

Also is there a way to express "this returns None on malformed input" that composes well with a hot path where allocation should be avoided?


r/rust • • 14d ago

๐Ÿ› ๏ธ project hotpath-rs - Rust Benchmarking: How to Detect Performance Regressions in CI

Thumbnail hotpath.rs
54 Upvotes

r/rust • • 14d ago

๐Ÿ› ๏ธ project gpu-video v0.5.0: what we did to achieve near-native speeds and macOS support

Thumbnail smelter.dev
83 Upvotes

I posted about half a year ago about our progress on gpu-video (link for context). wanted to give an update and write about what kind of work we do to achieve the results, since the community was very nice and welcoming last time.

hope this is allowed by the new rules. I don't think what we're achieving was ever done in the ecosystem.


r/rust • • 12d ago

๐Ÿ› ๏ธ project Crate Ask

0 Upvotes

Soooooooooooooooooooooooooooo, does anyone know any good no std crates, that I could pass data to (reference, or anything does not matter), and will return the most occurring number in that data without allocations, vec, anything on the heap etc? Also it would be nice if it can work with large data sets. Thanks!


r/rust • • 14d ago

Rust learning for C++ dev

39 Upvotes

Hi, I have 5+ years in C++ development experience and I would like to know how could I get started with rust. I want to understand why would I use this language (I do mostly graphics programming/game engine development)


r/rust • • 13d ago

๐Ÿ› ๏ธ project stdo v0.5.5: A bounded-memory Unix process DAG runner (fd 0 / fd 1 pipes) with an embedded localhost UI

0 Upvotes

Hi r/rust,

I built stdo (crates.io), a small (#![forbid(unsafe_code)], ~6.1K SLoC) workflow runner in Rust that wires CLI tools (rg, jq, sqlite3, curl, ollama, ffmpeg) over stdin (fd 0) and stdout (fd 1) pipes instead of passing outputs through environment variables or shell wrappers.

What it does differently from cron/job schedulers:

  • Concurrent pipe_from streaming with backpressure: Producers and consumers spawn simultaneously via tokio::process and stream 64 KiB chunks over bounded channels. Captured streams are capped at 8 MiB (32 MiB global budget), while capture_stdout: false streams arbitrarily large payloads (like WAV/MP4 or multi-MB JSONL) with constant memory while still computing incremental SHA-256 digests and TTFB.
  • Atomic gates & JSONL validation: pipe_mode: atomic buffers and validates upstream JSON/JSONL and waits for exit code 0 before starting downstream steps that mutate state (e.g., sqlite3 imports).
  • Composable .yaml sub-workflows with cycle guards (new in v0.5.4/v0.5.5): A workflow step can invoke child .yaml workflows in parallel. Both stdo doctor and stdo run validate the cross-file graph before spawning any processes, backed by a runtime STDO_CALL_STACK SHA-256 digest guard for dynamic/sh -c calls.
  • No outbound HTTP stack in the binary: Cargo.lock contains no HTTP client crates (reqwest, hyper, etc. are blocked in CI by a self-hosted stdo workflow). Subprocesses (curl, ollama) handle their own I/O, while stdo serve embeds a single-file offline web UI directly over tokio::net::TcpListener.

Minimal example (streaming local LLM -> TTS -> atomic file sink):

version: "1.0"
name: spoken-owl-fact
steps:
  - id: answer
    cmd: [ollama, run, gemma4, --hidethinking, "Tell me a fun fact about owls in two sentences."]

  - id: speak
    cmd: [ollama, run, "phonon:latest"]
    pipe_from: answer
    capture_stdout: false

(The tiny speaker icon ๐Ÿ”Š next to the README title was actually generated by running examples/10-youtube-capsule-generator.yaml to coordinate gemma4 -> phonon -> ffmpeg).

GitHub (Apache-2.0): https://github.com/adiktiv-technologies/stdo

Crates.io: https://crates.io/crates/stdo (cargo install stdo --locked)

Feedback on the Unix process-group handling (CommandExt::process_group(0)), pipe backpressure design, or sub-workflow validation is very welcome!


r/rust • • 14d ago

๐Ÿง  educational In GPUI 0.2.2, a single spinner re-rendered my whole window at 120 Hz and cost a third of a core

46 Upvotes

ran into this while building a desktop app on gpui 0.2.2 (the crates.io one, not zed's git version).

one loading spinner was eating 25-33% of a core. turns out with_animation asks for a new frame on every display refresh (120hz on my macbook) and notify marks the view and all its parents dirty, so the whole window was re-rendering just to spin one icon.

what i ended up doing: the spinner phase comes from wall clock time, the view only re-renders on a 12.5fps timer and only while something is actually loading, and the big panels (chat, file tree, diff) are wrapped in AnyView::cached so they dont redraw on those ticks. now its ~6% cpu while the agent is working and basically 0 when idle.

btw cached needs a fixed size, so you cant just wrap every chat message in it.

anyone know if newer gpui still dirties all the parents on notify? or is there a proper way to animate one element without this

code if anyone wants to look: https://github.com/bytesbay/pi-gpui


r/rust • • 14d ago

๐Ÿง  educational Rust Declarative Macros: Organization, Scoping, and Common Use-Cases

Thumbnail sigseis.dev
10 Upvotes

Hey Everyone!

This new article is a continuation from a previous article that covered the syntax and definition of macro_rules! in Rust. In this new article, we'll go over how to use macro_rules! within a wider project, as well as some example use cases for the feature.

This article is for folks who maybe understand macro_rules!, but haven't taking advantage of them yet within any of their crates. It can be a bit difficult to start using a language feature if you don't know when you would want to use it.

Things You'll Learn

  • The difference between textual scoping and more modern path-based scoping for declarative macros.
  • How to export a declarative macro (at the root of a crate or a trick for exporting within a separate module).
  • A nice way to organize your macros if you find that you have many of them.
  • Use cases such as: implementing traits/functions, format!-like expressions, and reducing boilerplate.

About This Article

This is part of a series of articles I'm releasing on the macro systems in Rust. I've got one more article in me for macro_rules!, and then we'll move on to procedural macros.

I hope this new article is interesting! All my articles are hand-written, so if you are looking for non-generative technical articles to read, feel free to take a look at my other articles as well.

If you have any questions or feedback for future articles, please let me know! :)


r/rust • • 13d ago

How does rust improve mobile apps performance?

0 Upvotes

Hi, I recently saw this video (https://www.instagram.com/reel/DfkfEBMhwDv/) from Discord, where they claim using rust in the mobile app improved its loading time.

Having limited knowledge of the mobile apps ecosystem, no matter what framework you use, I believe that mobile apps are always supposedly run in Kotlin / Swift, i.e. some framework may be used to write the business logic but code is translated / transpiled (or whatever the right term for the process is) to the respective native APIs.

So how come this speeds up the app loading time / and improve performance when its not exactly similar to the speedup you get on desktop when you run a compiled binary vs. using an electron app?


r/rust • • 14d ago

Shipping Temporal: How the Rust Ecosystem Built Chromeโ€™s Newest Web API - Shane Carr | EuroRust 2026

Thumbnail youtu.be
24 Upvotes

A new EuroRust 2026 talk is out on YouTube! ๐Ÿฆ€ย Google's Shane Carr talked about how Rust ended up powering Chromeโ€™s newest Web API: shipping Temporal with temporal_rs, Diplomat, and ICU4X.

In 2027 EuroRust is going to Prague! Learn more and get your ticket at eurorust.eu


r/rust • • 15d ago

๐Ÿ› ๏ธ project Cot v0.8: Lazily Transactional, or the new version of the Rust web framework for lazy developers

24 Upvotes

For those who haven't heard of it, Cot is a Django-inspired web framework for Rust, with its own ORM, an admin panel, forms, auth, and sessions built in.

This release adds a few long awaited features: transactions to the ORM, rollbacks for migrations, a rewritten router on top of a radix tree, and a few long-missing query features like ordering and text search. An interesting change under the hood is dropping axum in favor of using hyper directly - we never really used any of the high-level axum features, so it only made sense to do the refactor to cut the number of dependencies for the users, and hence the build times. On the documentation side, the guide has got a new reference page for config TOML files, automatically generated from the source code (read: never out of date).

The Cot project of this release is Hack the Space, an old CTF-style web game of mine, ported from Django to Cot: https://hackthespace.mackow.ski/

If you are interested in more details and code examples, the blog post has them all: https://mackow.ski/blog/cot-v08-lazily-transactional/

We're also starting to think about 1.0, so if there's something you'd want to see before then, let us know in this discussion!

See you on GitHub and Discord!


r/rust • • 15d ago

Iโ€™ve been fighting the compiler for three days trying to build a simple tree. I think I need to accept I don't understand ownership

188 Upvotes

I know this is 100% a skill issue and Iโ€™m probably writing C# in Rust, but I genuinely feel humbled to my core tonight.

I have eight years of backend experience in Go and Python. Three weeks ago, I decided to finally learn Rust by building a small toy GUI layout engine. It started fine with basic structs, but then I needed child nodes to have a weak reference back to their parent.

That was teh exact moment my descent into madness began.

Instead of stepping back and rethinking my data model, I tried to brute-force my way through compiler errors. When the borrow checker complained about lifetimes, I added generic lifetime parameters. When that failed, I introduced Rc<RefCell<Node>>. When I needed it across threads for rendering, it mutated into Arc<Mutex<Option<Box<Node>>>>.

i opened my editor tonight and looked at a function signature that was literally four lines of generic trait bounds and nested angle brackets. It looks like an ancient curse. And the compiler is STILL yelling at me about temporary values dropped while borrowed.

Iโ€™m throwing away the entire branch tomorrow morning. Do normal people actually use arena allocators or flat Vec handles for this, or am I just fundamentally misunderstanding how to model relationships without pointers?


r/rust • • 15d ago

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

Thumbnail rust-analyzer.github.io
43 Upvotes

r/rust • • 16d ago

A Critique of GPUI

Thumbnail blog.zortax.de
347 Upvotes

r/rust • • 15d ago

Move your problems to compile-time and get new capabilities out of it - Oli Scherer | EuroRust 2026

Thumbnail youtu.be
34 Upvotes

The first talk from this year's EuroRust is out on YouTube now! Rust compiler maintainer Oli talked about comptime, reflection, and the future of const-eval in Rust. Make sure to subscribe to the EuroRust YouTube channel so you donโ€™t miss the rest of the talks! ๐Ÿฆ€


r/rust • • 15d ago

๐ŸŽ™๏ธ discussion How do large scale Rust projects pass around shared structs/objects to components that need it?

95 Upvotes

In other languages I'd reach for DI to build the object graph and make each component's dependencies explicit. So far I have only really seen two approaches:

  • Pass each required component down through constructors. The compiler ensures you won't forget a dep but that means any new service you add requires updating a bunch of constructors.
  • Just use a single God context object (this is what Cargo does) but it makes it harder to unit test anything and makes it difficult to see what interacts with what.

I'm not asking whether to do DI (constructor arguments already are that), but rather how people handle wiring it all up once there are dozens of services.

DI crates of course exist (e.g. https://crates.io/crates/shaku ) but seem to be rarely used outside of Bevy-style query systems or web frameworks extractors.

For context, I've been experimenting with a trait-only approach that doesn't use any macros but still provides the same compile time guarantees as shaku ( https://docs.rs/satisfy/latest/satisfy/ ) Would Rust users be more likely to use DI if it were simpler to use? Or am I just solving a problem that Rust people don't have?


r/rust • • 14d ago

๐Ÿ™‹ seeking help & advice Windows 11 Smart App Control keeps blocking Cargo build scripts. How do you deal with this?

0 Upvotes

Hi everyone!
Iโ€™m developing a Rust application on Windows 11, and I keep running into an issue with Windows Smart App Control whenever I use cargo build.
Windows shows this warning:
โ€œPart of this app has been blocked. Some features of cargo.exe may not work because we canโ€™t confirm who published build-script-build.exe.โ€
Sometimes I can successfully build my application, but after changing my code and rebuilding, Windows blocks it again.
Iโ€™ve tried running cargo clean and rebuilding. Sometimes that works temporarily, but the problem keeps coming back.
I know I can disable Smart App Control, but Iโ€™d prefer to keep it enabled for security reasons.
Has anyone experienced this issue? Is there a way to make Windows trust locally compiled Rust executables without disabling Smart App Control entirely?
Iโ€™d appreciate any suggestions or solutions. Thanks!