From 19524f1ed14d8da8b3d953812a3c3b461085d3dc Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 2 Dec 2014 12:47:07 -0500 Subject: [PATCH] libcore: use unboxed closures in `Result` methods --- src/libcore/result.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 9d1ffa78911..88d33a59b38 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -239,6 +239,7 @@ use slice::AsSlice; use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator}; use option::Option; use option::Option::{None, Some}; +use ops::{FnMut, FnOnce}; /// `Result` is a type that represents either success (`Ok`) or failure (`Err`). /// @@ -466,7 +467,7 @@ impl Result { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - pub fn map(self, op: |T| -> U) -> Result { + pub fn map U>(self, op: F) -> Result { match self { Ok(t) => Ok(op(t)), Err(e) => Err(e) @@ -492,7 +493,7 @@ impl Result { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - pub fn map_err(self, op: |E| -> F) -> Result { + pub fn map_err F>(self, op: O) -> Result { match self { Ok(t) => Ok(t), Err(e) => Err(op(e)) @@ -612,7 +613,7 @@ impl Result { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - pub fn and_then(self, op: |T| -> Result) -> Result { + pub fn and_then Result>(self, op: F) -> Result { match self { Ok(t) => op(t), Err(e) => Err(e), @@ -666,7 +667,7 @@ impl Result { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - pub fn or_else(self, op: |E| -> Result) -> Result { + pub fn or_else Result>(self, op: O) -> Result { match self { Ok(t) => Ok(t), Err(e) => op(e), @@ -708,7 +709,7 @@ impl Result { /// ``` #[inline] #[unstable = "waiting for conventions"] - pub fn unwrap_or_else(self, op: |E| -> T) -> T { + pub fn unwrap_or_else T>(self, op: F) -> T { match self { Ok(t) => t, Err(e) => op(e) @@ -904,10 +905,11 @@ impl> FromIterator> for Result { pub fn fold V, Iter: Iterator>>( mut iterator: Iter, mut init: V, - f: |V, T| -> V) + mut f: F) -> Result { for t in iterator { match t {