Skip to content

Commit bf30a21

Browse files
committed
auto merge of #10967 : chris-morgan/rust/clean-and-tidy-some-traits, r=alexcrichton
### 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. ### Rename To{Str,Bytes}Consume traits to Into*. That is: - `ToStrConsume` → `IntoStr`; - `ToBytesConsume` → `IntoBytes`.
2 parents 3272b00 + b76997f commit bf30a21

File tree

7 files changed

+9
-450
lines changed

7 files changed

+9
-450
lines changed

src/etc/vim/syntax/rust.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ syn keyword rustEnumVariant Ok Err
6666

6767
" Types and traits {{{3
6868
syn keyword rustTrait Any AnyOwnExt AnyRefExt AnyMutRefExt
69-
syn keyword rustTrait Ascii AsciiCast OwnedAsciiCast AsciiStr ToBytesConsume
69+
syn keyword rustTrait Ascii AsciiCast OwnedAsciiCast AsciiStr IntoBytes
7070
syn keyword rustTrait Bool
7171
syn keyword rustTrait ToCStr
7272
syn keyword rustTrait Char
@@ -94,7 +94,7 @@ syn keyword rustTrait Buffer Writer Reader Seek
9494
syn keyword rustTrait SendStr SendStrOwned SendStrStatic IntoSendStr
9595
syn keyword rustTrait Str StrVector StrSlice OwnedStr
9696
syn keyword rustTrait IterBytes
97-
syn keyword rustTrait ToStr ToStrConsume
97+
syn keyword rustTrait ToStr IntoStr
9898
syn keyword rustTrait CopyableTuple ImmutableTuple
9999
syn keyword rustTrait Tuple1 Tuple2 Tuple3 Tuple4
100100
syn keyword rustTrait Tuple5 Tuple6 Tuple7 Tuple8

src/libstd/ascii.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! Operations on ASCII strings and characters.
1212
13-
use to_str::{ToStr,ToStrConsume};
13+
use to_str::{ToStr,IntoStr};
1414
use str;
1515
use str::StrSlice;
1616
use str::OwnedStr;
@@ -294,7 +294,7 @@ impl<'a> AsciiStr for &'a [Ascii] {
294294
}
295295
}
296296

297-
impl ToStrConsume for ~[Ascii] {
297+
impl IntoStr for ~[Ascii] {
298298
#[inline]
299299
fn into_str(self) -> ~str {
300300
unsafe { cast::transmute(self) }
@@ -309,12 +309,12 @@ impl IterBytes for Ascii {
309309
}
310310

311311
/// Trait to convert to a owned byte array by consuming self
312-
pub trait ToBytesConsume {
312+
pub trait IntoBytes {
313313
/// Converts to a owned byte array by consuming self
314314
fn into_bytes(self) -> ~[u8];
315315
}
316316

317-
impl ToBytesConsume for ~[Ascii] {
317+
impl IntoBytes for ~[Ascii] {
318318
fn into_bytes(self) -> ~[u8] {
319319
unsafe { cast::transmute(self) }
320320
}

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
}

0 commit comments

Comments
 (0)