Registry / utility / replace-with

replace-with

JSON →
library0.1.8rscratesunverified

Temporarily take ownership of a value at a mutable location, and replace it with a new value based on the old one.

# Cargo.toml [dependencies] replace_with = "0.1.8"
INSTALL
IMPORT
SIG · REPLACE-WITH
R
replace-with
utilityrustv0.1.8
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.

replace_with
use replace_with::replace_with;

Replace a mutable value with a new value computed from the old one.

use replace_with::replace_with; fn main() { let mut x = 42; replace_with(&mut x, |old| old + 1); assert_eq!(x, 43); }
Debug
Known issues
gotchaPanics if the closure panics, leaving the original value in an undefined state.
fix
Ensure closure does not panic or use std::mem::replace instead.
affects: >=0.1.0
Upgrade
Version history
0.1.8latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
replace-with — cargo add replace-with · libregistry