unsafe-binders 0.0.1

Stable rust polyfill of `unsafe<'lt> …` binders
Documentation
# `::unsafe-binders`

Stable rust polyfill of [`unsafe<'lt> …` binders](https://hackmd.io/@compiler-errors/HkXwoBPaR).

[![Repository](https://img.shields.io/badge/repository-GitHub-brightgreen.svg)](
https://github.com/danielhenrymantilla/unsafe-binders.rs)
[![Latest version](https://img.shields.io/crates/v/unsafe-binders.svg)](
https://crates.io/crates/unsafe-binders)
[![Documentation](https://docs.rs/unsafe-binders/badge.svg)](
https://docs.rs/unsafe-binders)
[![MSRV](https://img.shields.io/badge/MSRV-1.85.0-white)](
https://gist.github.com/danielhenrymantilla/9b59de4db8e5f2467ed008b3c450527b)
[![License](https://img.shields.io/crates/l/unsafe-binders.svg)](
https://github.com/danielhenrymantilla/unsafe-binders.rs/blob/master/LICENSE-ZLIB)
[![CI](https://github.com/danielhenrymantilla/unsafe-binders.rs/workflows/CI/badge.svg)](
https://github.com/danielhenrymantilla/unsafe-binders.rs/actions)
[![no_std compatible](https://img.shields.io/badge/no__std-compatible-success.svg)](
https://github.com/rust-secure-code/safety-dance/)

<!-- Templated by `cargo-generate` using https://github.com/danielhenrymantilla/proc-macro-template -->

---

Conceptually, unsafe binders are the way to express the `'unsafe/'never/'expired/'dangling` lifetime
used in certain `unsafe` constructs (_e.g._, self-referential data), in a way less unsoundness-prone
way as using `'static` instead would be:

  - by virtue of requiring `unsafe` to access the data,

  - and it not performing liveness or (lack-of-)aliasing assertions (courtesy of
    [`::maybe-dangling`]https://docs.rs/maybe-dangling, like `'static`-infected types may
    accidentally do.

# Example

```rust
use ::unsafe_binders::{DropMarker, Unsafe};

pub struct SelfReferential {
    full_name: String,
    first_name: Unsafe![DropMarker::NoDropGlue, <'this> &'this str],
                                           // using lifetime-elision shorthand syntax:
    last_name: Unsafe![DropMarker::NoDropGlue, &str],
}

impl SelfReferential {
    pub fn new(full_name: String) -> Option<Self> {
        let (first_name, last_name) = full_name.split_once(" ")?;
        // erase the `&'full_name` lifetime:
        let first_name: Unsafe![_, &str] = Unsafe::wrap_binder_copy(first_name);
                               // shorthand syntax
        let last_name: Unsafe![&str] = Unsafe::wrap_binder_copy(last_name);
        Some(Self {
            full_name,
            first_name,
            last_name,
        })
    }

    pub fn first_name<'r>(&'r self) -> &'r str {
        unsafe {
            self.first_name.unwrap_binder_ref::<'_, 'r>()
        }
    }

    pub fn last_name<'r>(&'r self) -> &'r str {
        unsafe {
            self.last_name.unwrap_binder_ref::<'_, 'r>()
        }
    }
}
```