diff --git a/src/libstd/option.rs b/src/libstd/option.rs index b68c67e8903b..f116c1127ca9 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -159,6 +159,17 @@ impl Option { } } + /// Update an optional value by optionally running its content by mut reference + /// through a function that returns an option. + #[inline] + pub fn chain_mut_ref<'a, U>(&'a mut self, f: &fn(x: &'a mut T) -> Option) + -> Option { + match *self { + Some(ref mut x) => f(x), + None => None + } + } + /// Filters an optional value using given function. #[inline(always)] pub fn filtered(self, f: &fn(t: &T) -> bool) -> Option {