From ff536f3fa59dc5d232724200e24af5eeae6f4b54 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 18 Jun 2012 12:57:06 -0700 Subject: [PATCH] core: Don't require copyable options where possible. Closes #2636 --- src/libcore/option.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index f9e147dbf1c9..98090ba8514b 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -87,20 +87,26 @@ pure fn unwrap(-opt: option) -> T unsafe { ret liberated_value; } -impl extensions for option { +impl extensions for option { #[doc = " Update an optional value by optionally running its content through a function that returns an option. "] fn chain(f: fn(T) -> option) -> option { chain(self, f) } - #[doc = "Returns the contained value or a default"] - fn get_default(def: T) -> T { get_default(self, def) } #[doc = "Applies a function to the contained value or returns a default"] fn map_default(def: U, f: fn(T) -> U) -> U { map_default(self, def, f) } #[doc = "Performs an operation on the contained value or does nothing"] fn iter(f: fn(T)) { iter(self, f) } + #[doc = "Returns true if the option equals `none`"] + fn is_none() -> bool { is_none(self) } + #[doc = "Returns true if the option contains some value"] + fn is_some() -> bool { is_some(self) } + #[doc = "Maps a `some` value from one type to another"] + fn map(f: fn(T) -> U) -> option { map(self, f) } +} +impl extensions for option { #[doc = " Gets the value out of an option @@ -109,12 +115,7 @@ impl extensions for option { Fails if the value equals `none` "] fn get() -> T { get(self) } - #[doc = "Returns true if the option equals `none`"] - fn is_none() -> bool { is_none(self) } - #[doc = "Returns true if the option contains some value"] - fn is_some() -> bool { is_some(self) } - #[doc = "Maps a `some` value from one type to another"] - fn map(f: fn(T) -> U) -> option { map(self, f) } + fn get_default(def: T) -> T { get_default(self, def) } } #[test]