SplitMut
A Rust library for safely retrieving multiple mutable values within the same collection.
get2_mut
, get3_mut
and get4_mut
return a tuple or 2, 3 or 4 values, each one of them being
one of:
Ok(&mut V)
Err(SplitMutError::NoValue)
in case there was no value for the key (i e, when your usualget_mut
would have returnedNone
)Err(SplitMutError::SameValue)
in case the same value has already been returned earlier in the tuple.
Add use splitmut::SplitMut
to your code have these functions implemented for mutable slices, Vec, VecDeque, HashMap and BTreeMap.
Example
extern crate splitmut;
use HashMap;
use ;
// Create a hashmap
let mut h = new;
h.insert;
h.insert;
// Swap two values easily
assert_eq!;
assert_eq!;
// Show error handling
let = h.get3_mut;
// No value for the key "0"
assert_eq!;
// First value for the key "1" is returned successfully
assert_eq!;
// Second value for the key "1" returns an error
assert_eq!;