Safely use (stack) references outside their original scope.
This library provides convenient runtime-checked out-of-scope handles that are:
!Send + !Sync
or (dependently) Send
/Sync
,Sync
or !Sync
values.Please see the documentation for more information about which to choose.
```rust use ref_portals::rc::Anchor;
let x = "Scoped".toowned();
let anchor = Anchor::new(&x);
let selfowned: Box
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!( "{}", *weakportal.upgrade(), // Panics iff the anchor has been dropped. ) }));
eternal(); // Scoped ```
ref-portals
strictly follows Semantic Versioning 2.0.0 with the following exceptions: