Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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