Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/storycraft/retained
Retain local variables between function calls
https://github.com/storycraft/retained
Last synced: about 1 month ago
JSON representation
Retain local variables between function calls
- Host: GitHub
- URL: https://github.com/storycraft/retained
- Owner: storycraft
- License: apache-2.0
- Created: 2024-06-01T10:27:11.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-23T03:59:06.000Z (6 months ago)
- Last Synced: 2024-11-01T18:42:38.850Z (about 2 months ago)
- Language: Rust
- Size: 1.96 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# `retained`
[Documentation](https://docs.rs/retained/latest)Keep local variables between repeated function calls using simple macro.
This crate is no_std.
## Usage
```rust no_run
use retained::retained;#[retained(DrawState)]
fn draw() {
#[retained]
let ref mut check_box: CheckBox = CheckBox::new(/* checked */ false);
check_box.draw();
}fn draw_loop() {
let mut state = DrawState::new();loop {
draw(&mut state);
}
}
```
Without `retained`, Checkbox's states would be reset on every `draw` call.
By using `retained`, local variable `check_box` is kept inside `DrawState` struct.
And `draw` function gets additional `&mut DrawState` argument.## Examples
See `examples` for simple example and egui demo ported using `retained`.## License
This crate is licensed under MIT OR Apache-2.0