Macro owned_pin::apin

source ·
macro_rules! apin {
    (let $value:ident = $init:expr) => { ... };
}
Expand description

Creates and pins an Arsc pointer on the current calling stack.

The syntax of this macro is different from the syntax of opin, due to its own implementation and the restriction on lifetime extensions of temporary values in Rust.

Examples

use owned_pin::sync::{Arsc, RefCount, RefCounted, apin};
use owned_pin::OnStack;

#[derive(RefCounted)]
struct A {
    value: &'static str,
    #[count_on]
    rc: RefCount,
}

// `arsc` is `Pin<Arsc<OnStack<A>>>`.
apin!(let arsc = A {
    value: "Hello!",
    rc: RefCount::new(),
});
// All the clones share the same lifetime.
let cloned = arsc.clone();