Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/storycraft/ref-extended
Achieve lifetime of value by shortening entire program lifetime
https://github.com/storycraft/ref-extended
rust rust-lifetime
Last synced: about 1 month ago
JSON representation
Achieve lifetime of value by shortening entire program lifetime
- Host: GitHub
- URL: https://github.com/storycraft/ref-extended
- Owner: storycraft
- License: mit
- Created: 2022-12-07T04:52:30.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-08T13:27:08.000Z (about 2 years ago)
- Last Synced: 2024-05-17T06:50:51.675Z (8 months ago)
- Topics: rust, rust-lifetime
- Language: Rust
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```Rust
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
```