From 56ecb51ba62b973e3a415cc0d6d6979dd7aeee7d Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 19 Nov 2014 18:06:41 -0500 Subject: [PATCH] libcore: use unboxed closures in `Option` methods --- src/libcore/option.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 5e2d6266f0ec..7be47f73e9ee 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -156,7 +156,7 @@ use result::Result::{Ok, Err}; use slice; use slice::AsSlice; use clone::Clone; -use ops::Deref; +use ops::{Deref, FnOnce}; // Note that this is not a lang item per se, but it has a hidden dependency on // `Iterator`, which is one. The compiler assumes that the `next` method of @@ -389,7 +389,7 @@ impl Option { /// ``` #[inline] #[unstable = "waiting for conventions"] - pub fn unwrap_or_else(self, f: || -> T) -> T { + pub fn unwrap_or_else T>(self, f: F) -> T { match self { Some(x) => x, None => f() @@ -413,7 +413,7 @@ impl Option { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - pub fn map(self, f: |T| -> U) -> Option { + pub fn map U>(self, f: F) -> Option { match self { Some(x) => Some(f(x)), None => None @@ -433,7 +433,7 @@ impl Option { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - pub fn map_or(self, def: U, f: |T| -> U) -> U { + pub fn map_or U>(self, def: U, f: F) -> U { match self { Some(t) => f(t), None => def @@ -455,7 +455,7 @@ impl Option { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - pub fn map_or_else(self, def: || -> U, f: |T| -> U) -> U { + pub fn map_or_else U, F: FnOnce(T) -> U>(self, def: D, f: F) -> U { match self { Some(t) => f(t), None => def() @@ -497,7 +497,7 @@ impl Option { /// ``` #[inline] #[experimental] - pub fn ok_or_else(self, err: || -> E) -> Result { + pub fn ok_or_else E>(self, err: F) -> Result { match self { Some(v) => Ok(v), None => Err(err()), @@ -615,7 +615,7 @@ impl Option { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - pub fn and_then(self, f: |T| -> Option) -> Option { + pub fn and_then Option>(self, f: F) -> Option { match self { Some(x) => f(x), None => None, @@ -667,7 +667,7 @@ impl Option { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - pub fn or_else(self, f: || -> Option) -> Option { + pub fn or_else Option>(self, f: F) -> Option { match self { Some(_) => self, None => f()