# No-Panic Rust: A Nice Technique for Systems Programming

DevFeed: [No-Panic Rust: A Nice Technique for Systems Programming](<https://devfeed.tech/articles/no-panic-rust-a-nice-technique-for-systems-programming-21139.md>)

Original publisher: [Read original article](<https://blog.reverberate.org/2025/02/03/no-panic-rust.html>)

Author: Haberman

Published: 2025-02-03T00:00:00Z

Content type: article

Language: en

Sources: [Josh Haberman](<https://devfeed.tech/sources/josh-haberman.md>)

Topics: [Rust](<https://devfeed.tech/topics/rust.md>), [systems](<https://devfeed.tech/topics/systems.md>), [Memory Safety](<https://devfeed.tech/topics/memory-safety.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [code](<https://devfeed.tech/tags/code.md>), [memory-safety](<https://devfeed.tech/tags/memory-safety.md>), [programming](<https://devfeed.tech/tags/programming.md>), [rust](<https://devfeed.tech/tags/rust.md>), [systems](<https://devfeed.tech/tags/systems.md>)

## AI overview

This article examines "No-Panic Rust," a technique for using Rust in low-level systems programming while avoiding panics as a response to errors. The author argues that the approach could make porting the upb C library to Rust more practical while preserving performance and code-size goals.

## Source excerpt

Can Rust replace C? This is a question that has been on my mind for many years, as I created and now am tech lead for upb, a C library for Protocol Buffers. There is an understandable push to bring memory safety to all parts of the software stack, and this would suggest a port of upb to Rust. While I love the premise of Rust, I have long been skeptical that a port of upb to Rust could preserve the performance and code size characteristics that I and others have fought so hard to optimize. In fact, this blog entry was originally going to be an argument for why Rust cannot match C for upb's use case. But I recently discovered a technique that shifted my thinking a lot. I call it "No-Panic Rust", and while the technique is clearly not new1, I was not able to find any in-depth discussion of how it works or what problems it solves. This article is my attempt to fill that gap. I believe that No-Panic Rust is the key to making Rust a compelling option for low-level systems programming. I now am optimistic about the possibility of porting upb to Rust. What are Panics? Panics are Rust's mechanism for unrecoverable errors. Anytime our program encounters an error, we have three basic options for how to handle it: Handle the error immediately (eg. retry the operation or fall back to plan B). Propagate the error to the caller, who can decide how to handle it. Immediately abort execution. In Rust, we use Result for (2) and panic!() for (3). When we use Result, it is considered a "recoverable error", because the caller can test for the error and decide how to respond. With recoverable errors, the potential for error is reflected in the function signature; a function that returns Result is fallible from the perspective of the caller. Panics on the other hand present the illusion of infallibility from an API perspective, but then proceed to handle errors by simply aborting. There is a lot of standard guidance for when to use panic!() vs Result (for example, here and here), which lar