#lifetime #value #reference #shortening #extended #achieve #abort

ref-extended

Achieve lifetime of value by shortening entire program lifetime

2 releases

0.2.1 Dec 8, 2022
0.2.0 Dec 8, 2022
0.1.3 Dec 7, 2022

#6 in #abort


Used in async-component-winit

MIT license

5KB
57 lines

Ref Extended

Extends lifetime of reference to same as lifetime of value by shortening entire program lifetime

When it is useful?

  1. You are doing programming without heap allocation (such as embed programming), and don't want to use static.
  2. You run some diverging functions which exit process itself without returning.

Example

let mut a = 2_i32; // The lifetime of value itself(not reference) is 'static

// Safely extend lifetimes and abort after expression finish
ref_extended!(|&a| {
    identity::<&'static i32>(a); // This compiles
});

// Unreachable. Process abort

No runtime deps