macro_rules! on_stack { ($value:expr) => { ... }; }
Expand description
Constructs a smart pointer on the current calling stack from the value.
Unlike other pointers like Box<T>, this returned pointer consumes no
additional memory on the heap, at the cost of restricted lifetime of the
current calling context.
This pointer serves no additional functionality, unless used with Pin.
Examples
// Basic usage
use owned_pin::{on_stack, IntoInner};
let pointer = on_stack!(String::from("Hello!"));
let string = IntoInner::into_inner(pointer);
assert_eq!(string, "Hello!");// Pinning the pointer
use owned_pin::{on_stack, OnStack};
let pointer = on_stack!(String::from("Hello!"));
let pinned = OnStack::into_pin(pointer);
// Use this pinned pointer while keeping the semantic ownership.