stealcell

Crates.iostealcell
lib.rsstealcell
version0.2.0
created_at2025-11-19 23:50:22.629047+00
updated_at2025-12-19 18:39:30.203688+00
descriptionAn Option like type that lets you temporarily remove a value from somewhere to retain mutable access on both.
homepagehttps://github.com/AlexAegis/stealcell
repositoryhttps://github.com/AlexAegis/stealcell
max_upload_size
id1940946
size11,469
Sandor (AlexAegis)

documentation

https://github.com/AlexAegis/stealcell

README

stealcell

crates.io ci codecov

An Option like type that lets you temporarily remove a value from somewhere to retain mutable access on both.

Example & Usage

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);
}

For Maintainers

See contributing.md

Commit count: 0

cargo fmt