Crates.io | update_cell |
lib.rs | update_cell |
version | 0.1.0 |
source | src |
created_at | 2023-07-21 12:59:38.912953 |
updated_at | 2023-07-21 12:59:38.912953 |
description | A Cell |
homepage | |
repository | https://github.com/YtvwlD/update_cell |
max_upload_size | |
id | 922398 |
size | 4,778 |
A Cell<Option<T>>
that you can update
[Cell::update
] is currently experimental. And it only supports types
that are Copy
. So if you want to store and modify something that is
neither Copy
nor has a Default
(eg. a builder), this crate might be
useful.
Add this to your Cargo.toml
:
[dependencies]
update_cell = "0.1"
And if you have a struct, you can put it inside and modify it:
use update_cell::UpdateCell;
struct MySuperFancyStruct {
inner: bool
}
impl MySuperFancyStruct {
fn new() -> Self {
Self { inner: false }
}
fn toggle(mut self) -> Self {
self.inner = !self.inner;
self
}
}
let mut cell = UpdateCell::new(MySuperFancyStruct::new());
cell.update(|s| s.toggle());
License: MPL-2.0