[−][src]Function idata::steal_borrow
pub fn steal_borrow<T>(target: &mut T, f: &dyn Fn(T) -> T)
&mut propagates mutability to top This is bad
You could have also a type working by owner shipt (to avoid mutability propagation)
In several cases you will have problems due to references
To avoid it, steal_borrow will let you execute as owner a function
extern crate idata; struct Ex { val1: u16, val2: u32, } impl Ex { fn inc(mut self) -> Self { self.val1 += 1; self.val2 += 2; self } } fn test(rm_ex: &mut Ex) { idata::steal_borrow(rm_ex, &|o : Ex| o.inc() ); } fn main() { let mut ex = Ex{ val1: 0, val2: 0}; test(&mut ex); assert!(ex.val1 == 1); assert!(ex.val2 == 2); }