Crates.io | retained |
lib.rs | retained |
version | 0.4.0 |
source | src |
created_at | 2024-06-01 10:30:04.073403 |
updated_at | 2024-06-21 11:26:56.908423 |
description | Retain local variables between function calls |
homepage | |
repository | https://github.com/storycraft/retained |
max_upload_size | |
id | 1258607 |
size | 2,269 |
retained
Keep local variables between repeated function calls using simple macro.
This crate is no_std.
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.
See examples
for simple example and egui demo ported using retained
.
This crate is licensed under MIT OR Apache-2.0