#lifetime #reference #no-alloc

no-std unsaferef

An unsafe reference without explicit lifetime

1 unstable release

new 0.1.0 Sep 28, 2024

#1899 in Rust patterns

Download history 90/week @ 2024-09-23

90 downloads per month

MIT license

8KB
154 lines

unsaferef

An unsafe reference without explicit lifetime

License CI status crates.io

Example

use unsaferef::UnsafeRef;

fn main() {
    let data = String::from("Hello, world!");

    // SAFETY: `data` is alive as long as `r` is in use
    let r: UnsafeRef<String> = unsafe {
        UnsafeRef::new(&data)
    };

    assert_eq!(*r, "Hello, world!");

    drop(data)
}

no-std and cow

UnsafeRef supports no-std::no-alloc.

On alloc feature ( default ), unsaferef additionally provides UnsafeCow, an unsafe Clone-on-Write container without explicit lifetime.

License

unsaferef is licensed under MIT LICENSE ( LICENSE or https://opensource.org/licenses/MIT ).

No runtime deps

Features