diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 643812312582e..fb9962f8a44ec 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -161,7 +161,7 @@ impl Option { /// Filters an optional value using given function. #[inline(always)] - pub fn filtered<'a>(self, f: &fn(t: &'a T) -> bool) -> Option { + pub fn filtered(self, f: &fn(t: &T) -> bool) -> Option { match self { Some(x) => if(f(&x)) {Some(x)} else {None}, None => None @@ -170,10 +170,16 @@ impl Option { /// Maps a `some` value from one type to another by reference #[inline] - pub fn map<'a, U>(&self, f: &fn(&'a T) -> U) -> Option { + pub fn map<'a, U>(&'a self, f: &fn(&'a T) -> U) -> Option { match *self { Some(ref x) => Some(f(x)), None => None } } + /// Maps a `some` value from one type to another by a mutable reference + #[inline] + pub fn map_mut<'a, U>(&'a mut self, f: &fn(&'a mut T) -> U) -> Option { + match *self { Some(ref mut x) => Some(f(x)), None => None } + } + /// As `map`, but consumes the option and gives `f` ownership to avoid /// copying. #[inline]