Registry / utility / take-mut

take-mut

JSON →
library0.2.2rscratesunverified

Allows taking ownership of a value from a mutable reference temporarily, replacing it with a default.

# Cargo.toml [dependencies] take_mut = "0.2.2"
INSTALL
IMPORT
SIG · TAKE-MUT
T
take-mut
utilityrustv0.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

take
use take_mut::take;

Temporarily take ownership of a value from a mutable reference.

use take_mut::take; fn main() { let mut x = String::from("hello"); take(&mut x, |old| { println!("Took: {}", old); String::from("world") }); println!("Now: {}", x); }
Debug
Known issues
gotchaPanics if the closure panics, leaving the original reference in an invalid state.
fix
Ensure the closure does not panic, or use a safe alternative like std::mem::take.
affects: >=0.1.0
Upgrade
Version history
0.2.2latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
12
Resources