Rustlang - sgml/signature GitHub Wiki
Runtime
Rust vs C++
| Scenario / Use Case | Why Replacing C++ With Rust Is Too Risky |
|---|---|
| Hard real‑time systems (RTOS, avionics, medical devices) | Rust lacks proven WCET analysis; LLVM optimizations introduce timing nondeterminism; certification toolchains are immature. |
| Systems requiring stable ABI | Rust has no stable ABI; long‑term binary compatibility for plugins, shared libraries, or kernel modules cannot be guaranteed. |
| Large legacy C++ codebases | Deep template metaprogramming, custom allocators, and undocumented invariants make rewrites expensive and destabilizing. |
| Vendor‑locked toolchain environments | Automotive, aerospace, and industrial systems rely on certified C++ compilers that Rust cannot replace without losing certification or support. |
| GPU programming (CUDA, HIP/ROCm, Metal) | GPU ecosystems are tightly coupled to C++; Rust GPU tooling is experimental and lacks vendor‑level debugging/profiling. |
| Memory‑constrained embedded systems | Rust monomorphization and safety abstractions can increase binary size and stack usage beyond microcontroller limits. |
| Deterministic destruction requirements | C++ RAII provides strict destruction timing; Rust’s drop semantics follow ownership rules that may not match required cleanup order. |
| Systems with decades of domain knowledge | Rewrites risk losing subtle performance hacks, undocumented behavior, and institutional knowledge embedded in C++ code. |
| Safety‑critical cryptography | Mature C++ crypto libraries have long verification histories; Rust crypto depends on LLVM optimizations that may break constant‑time guarantees. |
| Ultra‑low‑latency trading systems | Nanosecond‑level latency budgets can be disrupted by Rust’s abstraction overhead, register pressure, or inlining unpredictability. |
| Kernel or hypervisor development | Rust kernel support is emerging; unsafe‑block auditing, debugging, and tooling are less mature than C++ equivalents. |
| Long‑term maintenance environments | Industries requiring 20–40 year support windows cannot rely on Rust’s rapidly evolving ecosystem; C++ offers stable standards and frozen toolchains. |
Porting C
HTTPD Integration
use apache2::server::{APRSuccess, HTTP_MOVED_PERMANENTLY};
use apache2::{ApacheModule, Request, Status};
pub struct RedirectModule;
impl ApacheModule for RedirectModule {
fn handler(r: &mut Request) -> Status {
if r.uri().starts_with("/old-path") {
r.headers_out().add("Location", "http://example.com/new-path");
r.set_status(HTTP_MOVED_PERMANENTLY);
return Status::DONE; // Complete handling for the request
}
Status::DECLINED // Let other handlers process the request
}
}
Installer
cargo add apache2
Build
cargo build --release
httpd.conf
LoadModule redirect_module /usr/lib/apache2/modules/mod_redirect.rs.so
```
#### mod_test
t/TEST -start t/TEST -run
## Projects
```
tools:
text_editors:
- name: "Zed"
url: "https://zed.dev"
- name: "Helix"
url: "https://helix-editor.com"
- name: "Lapce"
url: "https://lapce.dev"
- name: "Kibi"
url: "https://github.com/ilai-deutel/kibi"
ides:
- name: "Lapce"
url: "https://lapce.dev"
- name: "Zed"
url: "https://zed.dev"
email_clients:
- name: "Himalaya"
url: "https://github.com/pimalaya/himalaya"
- name: "Lettre"
url: "https://docs.rs/lettre/latest/lettre/"
- name: "Email-lib"
url: "https://docs.rs/email-lib"
rest_clients:
- name: "Reqwest"
url: "https://github.com/seanmonstar/reqwest"
- name: "Hyper"
url: "https://hyper.rs"
- name: "Surf"
url: "https://github.com/http-rs/surf"
```
## Compiletime
* https://www.shuttle.rs/blog/2022/12/23/procedural-macros
* https://tembo.io/blog/postgres-extension-in-rust-pgmq
## Complexity
Closures & Lambdas: The Rust idiom `let add = |x, y| x + y;` uses an anonymous function with environment capture, which cannot be mapped to another language that does not implement this natively.
Pattern Matching: Rust's match statement supports deep pattern matching (with nested or complex patterns) that has no direct counterpart with `IF...ELSE` or `SELECT CASE...WHEN`. A regex approach would fail to capture nested patterns reliably.
Generics and Trait Bounds: complex type inference and compile‑time checking cannot be simply mapped from Rust to another language.
Async/Await Patterns: asynchronous primitives cannot be mapped to a synchronous execution model.
Macros: Compile‑time code generation cannot be mapped to another language.
Unsafe Blocks & Pointer Arithmetic: Pointer memory operations cannot be mapped to another language.
## Assertion
Rust assertions can be disabled by the `debug_assert!` macro.
## Rust for Basic Devs
| Regex | Rust Code | QBasic Code |
|-----------------------------------|------------------------------------|----------------------------|
| `let (\w+) = (.+);` | `let x = 42;` | `x = 42` |
| `println!\("(.*)"\);` | `println!("Hello, world!");` | `PRINT "Hello, world!"` |
| `fn (\w+)\(.*\) {` | `fn add(a: i32, b: i32) {` | `FUNCTION add(a, b)` |