No-Panic Rust: Can Rust Replace C for Low-Level Systems Programming?
This article explores the feasibility of using Rust to replace C for low-level systems programming, specifically focusing on a Protocol Buffers library called upb. The author initially doubted Rust's ability to match C in performance and code size but discovered a technique called "No-Panic Rust." This involves avoiding the use of `panic!()`. The article delves into the principles, advantages, and challenges of No-Panic Rust, including code size, unrecoverable exits, and runtime overhead. It demonstrates how to write No-Panic Rust code using techniques such as leveraging the libc library, optimization options, and `std::hint::assert_unchecked`, emphasizing the retention of overflow checks in debug mode for extra consistency checks. While this technique demands meticulous work and may necessitate avoiding most of the standard library, it promises to deliver the performance and code size of a C library while retaining Rust's safety guarantees.