core: Don't require copyable options where possible. Closes #2636

This commit is contained in:
Brian Anderson 2012-06-18 12:57:06 -07:00
parent f87c28b122
commit ff536f3fa5

View File

@ -87,20 +87,26 @@ pure fn unwrap<T>(-opt: option<T>) -> T unsafe {
ret liberated_value;
}
impl extensions<T:copy> for option<T> {
impl extensions<T> for option<T> {
#[doc = "
Update an optional value by optionally running its content through a
function that returns an option.
"]
fn chain<U>(f: fn(T) -> option<U>) -> option<U> { 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<U: copy>(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<U:copy>(f: fn(T) -> U) -> option<U> { map(self, f) }
}
impl extensions<T: copy> for option<T> {
#[doc = "
Gets the value out of an option
@ -109,12 +115,7 @@ impl extensions<T:copy> for option<T> {
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<U:copy>(f: fn(T) -> U) -> option<U> { map(self, f) }
fn get_default(def: T) -> T { get_default(self, def) }
}
#[test]