reem / rust-modifier

Convenient chaining APIs for free
29 stars 9 forks source link

Add modifier function wrapper #22

Closed zakarumych closed 8 years ago

zakarumych commented 8 years ago

Allow to modify values &mut T values with functions/closures that implements FnOnce(T) -> T

reem commented 8 years ago

Unfortunately, this is not safe. If the modifying function panics, the &mut T will be left pointing to uninitialized memory, causing undefined behavior.

zakarumych commented 8 years ago

So there is no other way I guess.

reem commented 8 years ago

@SCareAngel you might be interested in the take_mut crate (crates.io/crates/take_mut) which provides a similar API.

zakarumych commented 8 years ago

@reem, it is interesting. While doing exactly the same it also terminate the program in case of sudden panic. So it can be used with caution. Thank you for link