ref-portals

Latest Version docs.rs

Safely use (stack) references outside their original scope.

This library provides convenient runtime-checked out-of-scope handles that are:

Please see the documentation for more information about which to choose.

Example

```rust use ref_portals::rc::Anchor;

let x = "Scoped".toowned(); let anchor = Anchor::new(&x); let selfowned: Box = Box::new({ let portal = anchor.portal(); move || println!("{}", *portal) });

self_owned(); // Scoped ```

Note that dropping anchor before self_owned would still cause a panic here.
You can use weak portals to work around this:

```rust use ref_portals::rc::Anchor;

let x = "Scoped".toowned(); let anchor = Anchor::new(&x); let eternal: &'static dyn Fn() = Box::leak(Box::new({ let weakportal = anchor.weakportal(); move || println!( "{}", // Panics iff the anchor has been dropped. *weakportal.upgrade(), ) }));

eternal(); // Scoped ```

Versioning

ref-portals strictly follows Semantic Versioning 2.0.0 with the following exceptions: