9 个版本 (4 个重大更新)
| 0.4.0 | 2024 年 6 月 21 日 |
|---|---|
| 0.3.0 | 2024 年 6 月 20 日 |
| 0.2.0 | 2024 年 6 月 7 日 |
| 0.1.0 | 2024 年 6 月 6 日 |
| 0.0.4 | 2024 年 6 月 5 日 |
#100 在 缓存
每月 587 次下载
4KB
保留
使用简单的宏在重复的函数调用间保持局部变量。
此 crate 是 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);
}
}
在没有 retained 的情况下,复选框的状态会在每次 draw 调用后重置。通过使用 retained,局部变量 check_box 被保留在 DrawState 结构体中。并且 draw 函数获得了额外的 &mut DrawState 参数。
示例
请参阅 examples 中的简单示例以及使用 retained 端口化的 egui 演示。
许可证
此 crate 根据 MIT OR Apache-2.0 许可。
依赖项
~255–700KB
~17K SLoC