diff --git a/src/libstd/option.rs b/src/libstd/option.rs index ad81dfd65170..e40666b8a33a 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -42,11 +42,9 @@ use clone::Clone; use clone::DeepClone; use cmp::{Eq, TotalEq, TotalOrd}; use default::Default; -use either; use fmt; use iter::{Iterator, DoubleEndedIterator, ExactSize}; use kinds::Send; -use num::Zero; use result::{IntoResult, ToResult, AsResult}; use result::{Result, Ok, Err}; use str::OwnedStr; @@ -361,17 +359,6 @@ impl Option { } } -impl Option { - /// Returns the contained value or zero (for this type) - #[inline] - pub fn unwrap_or_zero(self) -> T { - match self { - Some(x) => x, - None => Zero::zero() - } - } -} - ///////////////////////////////////////////////////////////////////////////// // Constructor extension trait ///////////////////////////////////////////////////////////////////////////// @@ -449,26 +436,6 @@ impl AsResult for Option { } } -impl either::ToEither<(), T> for Option { - #[inline] - fn to_either(&self) -> either::Either<(), T> { - match *self { - Some(ref x) => either::Right(x.clone()), - None => either::Left(()), - } - } -} - -impl either::IntoEither<(), T> for Option { - #[inline] - fn into_either(self) -> either::Either<(), T> { - match self { - Some(x) => either::Right(x), - None => either::Left(()), - } - } -} - impl fmt::Default for Option { #[inline] fn fmt(s: &Option, f: &mut fmt::Formatter) { @@ -526,8 +493,6 @@ impl ExactSize for OptionIterator {} mod tests { use super::*; - use either::{IntoEither, ToEither}; - use either; use result::{IntoResult, ToResult}; use result::{Result, Ok, Err}; use str::StrSlice; @@ -696,14 +661,6 @@ mod tests { assert_eq!(x.unwrap_or_else(|| 2), 2); } - #[test] - fn test_unwrap_or_zero() { - let some_stuff = Some(42); - assert_eq!(some_stuff.unwrap_or_zero(), 42); - let no_stuff: Option = None; - assert_eq!(no_stuff.unwrap_or_zero(), 0); - } - #[test] fn test_filtered() { let some_stuff = Some(42); @@ -820,22 +777,4 @@ mod tests { assert_eq!(some.into_result(), Ok(100)); assert_eq!(none.into_result(), Err(())); } - - #[test] - pub fn test_to_either() { - let some: Option = Some(100); - let none: Option = None; - - assert_eq!(some.to_either(), either::Right(100)); - assert_eq!(none.to_either(), either::Left(())); - } - - #[test] - pub fn test_into_either() { - let some: Option = Some(100); - let none: Option = None; - - assert_eq!(some.into_either(), either::Right(100)); - assert_eq!(none.into_either(), either::Left(())); - } } diff --git a/src/libstd/result.rs b/src/libstd/result.rs index dcc910281ab2..768de7dfc1f8 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -13,7 +13,6 @@ use any::Any; use clone::Clone; use cmp::Eq; -use either; use fmt; use iter::Iterator; use kinds::Send; @@ -331,36 +330,6 @@ impl AsOption for Result { } } -impl either::ToEither for Result { - #[inline] - fn to_either(&self) -> either::Either { - match *self { - Ok(ref t) => either::Right(t.clone()), - Err(ref e) => either::Left(e.clone()), - } - } -} - -impl either::IntoEither for Result { - #[inline] - fn into_either(self) -> either::Either { - match self { - Ok(t) => either::Right(t), - Err(e) => either::Left(e), - } - } -} - -impl either::AsEither for Result { - #[inline] - fn as_either<'a>(&'a self) -> either::Either<&'a E, &'a T> { - match *self { - Ok(ref t) => either::Right(t), - Err(ref e) => either::Left(e), - } - } -} - impl fmt::Default for Result { #[inline] fn fmt(s: &Result, f: &mut fmt::Formatter) { @@ -444,8 +413,6 @@ pub fn fold_>>( mod tests { use super::*; - use either::{IntoEither, ToEither, AsEither}; - use either; use iter::range; use option::{IntoOption, ToOption, AsOption}; use option::{Option, Some, None}; @@ -631,33 +598,6 @@ mod tests { assert_eq!(err.as_result(), Err(&x)); } - #[test] - pub fn test_to_either() { - let ok: Result = Ok(100); - let err: Result = Err(404); - - assert_eq!(ok.to_either(), either::Right(100)); - assert_eq!(err.to_either(), either::Left(404)); - } - - #[test] - pub fn test_into_either() { - let ok: Result = Ok(100); - let err: Result = Err(404); - - assert_eq!(ok.into_either(), either::Right(100)); - assert_eq!(err.into_either(), either::Left(404)); - } - - #[test] - pub fn test_as_either() { - let ok: Result = Ok(100); - let err: Result = Err(404); - - assert_eq!(ok.as_either().unwrap_right(), &100); - assert_eq!(err.as_either().unwrap_left(), &404); - } - #[test] pub fn test_to_str() { let ok: Result = Ok(100);