| Crates.io | stealcell |
| lib.rs | stealcell |
| version | 0.2.0 |
| created_at | 2025-11-19 23:50:22.629047+00 |
| updated_at | 2025-12-19 18:39:30.203688+00 |
| description | An Option like type that lets you temporarily remove a value from somewhere to retain mutable access on both. |
| homepage | https://github.com/AlexAegis/stealcell |
| repository | https://github.com/AlexAegis/stealcell |
| max_upload_size | |
| id | 1940946 |
| size | 11,469 |
An Option like type that lets you temporarily remove a value from somewhere to retain mutable access on both.
cargo run --example stealcell_example
use stealcell::StealCell;
struct Thing {
value: usize,
}
impl Thing {
/// A test function that requires mutable access on itself and za warudo
fn hello_world(&mut self, world: &mut World) {
println!("hello {}, my value is {}.", world.name, self.value);
}
}
struct World {
name: String,
thing: StealCell<Thing>,
}
fn main() {
let mut world = World {
name: "world".to_string(),
thing: StealCell::new(Thing { value: 1 }),
};
let mut stolen_thing = world.thing.steal();
stolen_thing.hello_world(&mut world);
// If you skip this and let the stolen value drop, you get a panic!
world.thing.return_stolen(stolen_thing);
}
See contributing.md