Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ytvwld/update_cell
A Cell<Option<T>> that you can update
https://github.com/ytvwld/update_cell
Last synced: 7 days ago
JSON representation
A Cell<Option<T>> that you can update
- Host: GitHub
- URL: https://github.com/ytvwld/update_cell
- Owner: YtvwlD
- Created: 2023-07-21T12:35:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-21T12:58:49.000Z (over 1 year ago)
- Last Synced: 2024-10-10T18:56:37.725Z (28 days ago)
- Language: Rust
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# update_cell
A `Cell>` that you can update
## Why would I need this?
[`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.## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
update_cell = "0.1"
```And if you have a struct, you can put it inside and modify it:
```rust
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