update_cell 0.1.0

A Cell<Option<T>> that you can update
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented1 out of 5 items with examples
  • Size
  • Source code size: 17.62 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 257.14 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • YtvwlD/update_cell
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • YtvwlD

update_cell

A Cell<Option<T>> 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:

[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