#zero-cost #macro #no-unsafe

safe-rust

A safety-oriented Rust crate that ensures your code is safe

2 releases

0.1.1 Feb 3, 2026
0.1.0 Feb 3, 2026

#1865 in Rust patterns

MIT/Apache

5KB

safe-rust

safe-rust is a lightweight Rust crate designed to make your code safe.

Rust is already safe, but sometimes that’s not enough.

In situations where safety is critical, explicit, and non-negotiable, safe-rust allows you to clearly communicate that intent.

Features

  • Ensures expressions are safe
  • Zero-cost abstraction
  • No unsafe code
  • Minimal API surface
  • Explicit safety semantics

Installation

[dependencies]
safe-rust = "0.1"

Usage

use safe_rust::safe;

fn main() {
    // Guarantees that 2 + 2 is performed within safe boundaries
    let result = safe!(2 + 2);
    println!("{result}");
}

Recommendations

Safety

This crate contains no unsafe code.

All expressions passed to safe! are evaluated safely, as intended by the Rust language and its guarantees.

  • If an expression is unsafe, it should not compile.

  • If it compiles, it is safe.

Performance

There is no measurable performance impact. The macro expands directly to the enclosed expression, introducing no additional:

  • Instructions

  • Allocations

  • Runtime checks

Decision Matrix

When should I use this?

  • When you want to explicitly mark code as safe.

  • When safety is a concern.

  • When clarity matters.

  • When reviewing critical code paths.

  • When you want to be absolutely sure.

When should I not use this?

  • When safety is implied.

  • When ambiguity is acceptable.

  • When you are comfortable assuming safety.

No runtime deps