Skip to content

Commit 529f915

Browse files
committed
Remove {As,Into,To}{Option,Either,Result} traits.
Expanded, that is: - `AsOption` - `IntoOption` - `ToOption` - `AsEither` - `IntoEither` - `ToEither` - `AsResult` - `IntoResult` - `ToResult` These were defined for each other but never *used* anywhere. They are all trivial and so removal will have negligible effect upon anyone. `Either` has fallen out of favour (and its implementation of these traits of dubious semantics), `Option<T>` → `Result<T, ()>` was never really useful and `Result<T, E>` → `Option<T>` should now be done with `Result.ok()` (mirrored with `Result.err()` for even more usefulness). In summary, there's really no point in any of these remaining.
1 parent 8440036 commit 529f915

File tree

3 files changed

+0
-441
lines changed

3 files changed

+0
-441
lines changed

src/libstd/either.rs

Lines changed: 0 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313
#[allow(missing_doc)];
1414

1515
use option::{Some, None};
16-
use option;
1716
use clone::Clone;
1817
use container::Container;
1918
use cmp::Eq;
2019
use iter::{Iterator, FilterMap};
21-
use result::Result;
22-
use result;
2320
use str::StrSlice;
2421
use vec;
2522
use vec::{OwnedVector, ImmutableVector};
@@ -105,101 +102,6 @@ impl<L, R> Either<L, R> {
105102
}
106103
}
107104

108-
/// A generic trait for converting a value to a `Either`
109-
pub trait ToEither<L, R> {
110-
/// Convert to the `either` type
111-
fn to_either(&self) -> Either<L, R>;
112-
}
113-
114-
/// A generic trait for converting a value to a `Either`
115-
pub trait IntoEither<L, R> {
116-
/// Convert to the `either` type
117-
fn into_either(self) -> Either<L, R>;
118-
}
119-
120-
/// A generic trait for converting a value to a `Either`
121-
pub trait AsEither<L, R> {
122-
/// Convert to the `either` type
123-
fn as_either<'a>(&'a self) -> Either<&'a L, &'a R>;
124-
}
125-
126-
impl<L, R: Clone> option::ToOption<R> for Either<L, R> {
127-
#[inline]
128-
fn to_option(&self)-> option::Option<R> {
129-
match *self {
130-
Left(_) => None,
131-
Right(ref r) => Some(r.clone()),
132-
}
133-
}
134-
}
135-
136-
impl<L, R> option::IntoOption<R> for Either<L, R> {
137-
#[inline]
138-
fn into_option(self)-> option::Option<R> {
139-
match self {
140-
Left(_) => None,
141-
Right(r) => Some(r),
142-
}
143-
}
144-
}
145-
146-
impl<L, R> option::AsOption<R> for Either<L, R> {
147-
#[inline]
148-
fn as_option<'a>(&'a self) -> option::Option<&'a R> {
149-
match *self {
150-
Left(_) => None,
151-
Right(ref r) => Some(r),
152-
}
153-
}
154-
}
155-
156-
impl<L: Clone, R: Clone> result::ToResult<R, L> for Either<L, R> {
157-
#[inline]
158-
fn to_result(&self)-> result::Result<R, L> {
159-
match *self {
160-
Left(ref l) => result::Err(l.clone()),
161-
Right(ref r) => result::Ok(r.clone()),
162-
}
163-
}
164-
}
165-
166-
impl<L, R> result::IntoResult<R, L> for Either<L, R> {
167-
#[inline]
168-
fn into_result(self)-> result::Result<R, L> {
169-
match self {
170-
Left(l) => result::Err(l),
171-
Right(r) => result::Ok(r),
172-
}
173-
}
174-
}
175-
176-
impl<L, R> result::AsResult<R, L> for Either<L, R> {
177-
#[inline]
178-
fn as_result<'a>(&'a self) -> result::Result<&'a R, &'a L> {
179-
match *self {
180-
Left(ref l) => result::Err(l),
181-
Right(ref r) => result::Ok(r),
182-
}
183-
}
184-
}
185-
186-
impl<L: Clone, R: Clone> ToEither<L, R> for Either<L, R> {
187-
fn to_either(&self) -> Either<L, R> { self.clone() }
188-
}
189-
190-
impl<L, R> IntoEither<L, R> for Either<L, R> {
191-
fn into_either(self) -> Either<L, R> { self }
192-
}
193-
194-
impl<L, R> AsEither<L, R> for Either<L, R> {
195-
fn as_either<'a>(&'a self) -> Either<&'a L, &'a R> {
196-
match *self {
197-
Left(ref l) => Left(l),
198-
Right(ref r) => Right(r),
199-
}
200-
}
201-
}
202-
203105
/// An iterator yielding the `Left` values of its source
204106
pub type Lefts<L, R, Iter> = FilterMap<'static, Either<L, R>, L, Iter>;
205107

@@ -251,11 +153,6 @@ pub fn partition<L, R>(eithers: ~[Either<L, R>]) -> (~[L], ~[R]) {
251153
mod tests {
252154
use super::*;
253155

254-
use option::{IntoOption, ToOption, AsOption};
255-
use option;
256-
use result::{IntoResult, ToResult, AsResult};
257-
use result;
258-
259156
#[test]
260157
fn test_either_left() {
261158
let val = Left(10);
@@ -348,88 +245,4 @@ mod tests {
348245
assert_eq!(lefts.len(), 0u);
349246
assert_eq!(rights.len(), 0u);
350247
}
351-
352-
#[test]
353-
pub fn test_to_option() {
354-
let right: Either<int, int> = Right(100);
355-
let left: Either<int, int> = Left(404);
356-
357-
assert_eq!(right.to_option(), option::Some(100));
358-
assert_eq!(left.to_option(), option::None);
359-
}
360-
361-
#[test]
362-
pub fn test_into_option() {
363-
let right: Either<int, int> = Right(100);
364-
let left: Either<int, int> = Left(404);
365-
366-
assert_eq!(right.into_option(), option::Some(100));
367-
assert_eq!(left.into_option(), option::None);
368-
}
369-
370-
#[test]
371-
pub fn test_as_option() {
372-
let right: Either<int, int> = Right(100);
373-
let left: Either<int, int> = Left(404);
374-
375-
assert_eq!(right.as_option().unwrap(), &100);
376-
assert_eq!(left.as_option(), option::None);
377-
}
378-
379-
#[test]
380-
pub fn test_to_result() {
381-
let right: Either<int, int> = Right(100);
382-
let left: Either<int, int> = Left(404);
383-
384-
assert_eq!(right.to_result(), result::Ok(100));
385-
assert_eq!(left.to_result(), result::Err(404));
386-
}
387-
388-
#[test]
389-
pub fn test_into_result() {
390-
let right: Either<int, int> = Right(100);
391-
let left: Either<int, int> = Left(404);
392-
393-
assert_eq!(right.into_result(), result::Ok(100));
394-
assert_eq!(left.into_result(), result::Err(404));
395-
}
396-
397-
#[test]
398-
pub fn test_as_result() {
399-
let right: Either<int, int> = Right(100);
400-
let left: Either<int, int> = Left(404);
401-
402-
let x = 100;
403-
assert_eq!(right.as_result(), result::Ok(&x));
404-
405-
let x = 404;
406-
assert_eq!(left.as_result(), result::Err(&x));
407-
}
408-
409-
#[test]
410-
pub fn test_to_either() {
411-
let right: Either<int, int> = Right(100);
412-
let left: Either<int, int> = Left(404);
413-
414-
assert_eq!(right.to_either(), Right(100));
415-
assert_eq!(left.to_either(), Left(404));
416-
}
417-
418-
#[test]
419-
pub fn test_into_either() {
420-
let right: Either<int, int> = Right(100);
421-
let left: Either<int, int> = Left(404);
422-
423-
assert_eq!(right.into_either(), Right(100));
424-
assert_eq!(left.into_either(), Left(404));
425-
}
426-
427-
#[test]
428-
pub fn test_as_either() {
429-
let right: Either<int, int> = Right(100);
430-
let left: Either<int, int> = Left(404);
431-
432-
assert_eq!(right.as_either().unwrap_right(), &100);
433-
assert_eq!(left.as_either().unwrap_left(), &404);
434-
}
435248
}

src/libstd/option.rs

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ use default::Default;
4545
use fmt;
4646
use iter::{Iterator, DoubleEndedIterator, ExactSize};
4747
use kinds::Send;
48-
use result::{IntoResult, ToResult, AsResult};
49-
use result::{Result, Ok, Err};
5048
use str::OwnedStr;
5149
use to_str::ToStr;
5250
use util;
@@ -359,83 +357,10 @@ impl<T: Default> Option<T> {
359357
}
360358
}
361359

362-
/////////////////////////////////////////////////////////////////////////////
363-
// Constructor extension trait
364-
/////////////////////////////////////////////////////////////////////////////
365-
366-
/// A generic trait for converting a value to a `Option`
367-
pub trait ToOption<T> {
368-
/// Convert to the `option` type
369-
fn to_option(&self) -> Option<T>;
370-
}
371-
372-
/// A generic trait for converting a value to a `Option`
373-
pub trait IntoOption<T> {
374-
/// Convert to the `option` type
375-
fn into_option(self) -> Option<T>;
376-
}
377-
378-
/// A generic trait for converting a value to a `Option`
379-
pub trait AsOption<T> {
380-
/// Convert to the `option` type
381-
fn as_option<'a>(&'a self) -> Option<&'a T>;
382-
}
383-
384-
impl<T: Clone> ToOption<T> for Option<T> {
385-
#[inline]
386-
fn to_option(&self) -> Option<T> { self.clone() }
387-
}
388-
389-
impl<T> IntoOption<T> for Option<T> {
390-
#[inline]
391-
fn into_option(self) -> Option<T> { self }
392-
}
393-
394-
impl<T> AsOption<T> for Option<T> {
395-
#[inline]
396-
fn as_option<'a>(&'a self) -> Option<&'a T> {
397-
match *self {
398-
Some(ref x) => Some(x),
399-
None => None,
400-
}
401-
}
402-
}
403-
404360
/////////////////////////////////////////////////////////////////////////////
405361
// Trait implementations
406362
/////////////////////////////////////////////////////////////////////////////
407363

408-
impl<T: Clone> ToResult<T, ()> for Option<T> {
409-
#[inline]
410-
fn to_result(&self) -> Result<T, ()> {
411-
match *self {
412-
Some(ref x) => Ok(x.clone()),
413-
None => Err(()),
414-
}
415-
}
416-
}
417-
418-
impl<T> IntoResult<T, ()> for Option<T> {
419-
#[inline]
420-
fn into_result(self) -> Result<T, ()> {
421-
match self {
422-
Some(x) => Ok(x),
423-
None => Err(()),
424-
}
425-
}
426-
}
427-
428-
impl<T> AsResult<T, ()> for Option<T> {
429-
#[inline]
430-
fn as_result<'a>(&'a self) -> Result<&'a T, &'a ()> {
431-
static UNIT: () = ();
432-
match *self {
433-
Some(ref t) => Ok(t),
434-
None => Err(&UNIT),
435-
}
436-
}
437-
}
438-
439364
impl<T: fmt::Default> fmt::Default for Option<T> {
440365
#[inline]
441366
fn fmt(s: &Option<T>, f: &mut fmt::Formatter) {
@@ -493,8 +418,6 @@ impl<A> ExactSize<A> for OptionIterator<A> {}
493418
mod tests {
494419
use super::*;
495420

496-
use result::{IntoResult, ToResult};
497-
use result::{Ok, Err};
498421
use str::StrSlice;
499422
use util;
500423

@@ -732,49 +655,4 @@ mod tests {
732655
assert!(!x.mutate_default(0i, |i| i+1));
733656
assert_eq!(x, Some(0i));
734657
}
735-
736-
#[test]
737-
pub fn test_to_option() {
738-
let some: Option<int> = Some(100);
739-
let none: Option<int> = None;
740-
741-
assert_eq!(some.to_option(), Some(100));
742-
assert_eq!(none.to_option(), None);
743-
}
744-
745-
#[test]
746-
pub fn test_into_option() {
747-
let some: Option<int> = Some(100);
748-
let none: Option<int> = None;
749-
750-
assert_eq!(some.into_option(), Some(100));
751-
assert_eq!(none.into_option(), None);
752-
}
753-
754-
#[test]
755-
pub fn test_as_option() {
756-
let some: Option<int> = Some(100);
757-
let none: Option<int> = None;
758-
759-
assert_eq!(some.as_option().unwrap(), &100);
760-
assert_eq!(none.as_option(), None);
761-
}
762-
763-
#[test]
764-
pub fn test_to_result() {
765-
let some: Option<int> = Some(100);
766-
let none: Option<int> = None;
767-
768-
assert_eq!(some.to_result(), Ok(100));
769-
assert_eq!(none.to_result(), Err(()));
770-
}
771-
772-
#[test]
773-
pub fn test_into_result() {
774-
let some: Option<int> = Some(100);
775-
let none: Option<int> = None;
776-
777-
assert_eq!(some.into_result(), Ok(100));
778-
assert_eq!(none.into_result(), Err(()));
779-
}
780658
}

0 commit comments

Comments
 (0)