Remove CloneableTuple and ImmutableTuple traits
These are adequately covered by the Tuple2 trait.
This commit is contained in:
parent
cf0654c47c
commit
f450b2b379
9 changed files with 11 additions and 91 deletions
|
|
@ -95,13 +95,9 @@ syn keyword rustTrait Buffer Writer Reader Seek
|
|||
syn keyword rustTrait Str StrVector StrSlice OwnedStr IntoMaybeOwned
|
||||
syn keyword rustTrait IterBytes
|
||||
syn keyword rustTrait ToStr IntoStr
|
||||
syn keyword rustTrait CloneableTuple ImmutableTuple
|
||||
syn keyword rustTrait Tuple1 Tuple2 Tuple3 Tuple4
|
||||
syn keyword rustTrait Tuple5 Tuple6 Tuple7 Tuple8
|
||||
syn keyword rustTrait Tuple9 Tuple10 Tuple11 Tuple12
|
||||
syn keyword rustTrait ImmutableTuple1 ImmutableTuple2 ImmutableTuple3 ImmutableTuple4
|
||||
syn keyword rustTrait ImmutableTuple5 ImmutableTuple6 ImmutableTuple7 ImmutableTuple8
|
||||
syn keyword rustTrait ImmutableTuple9 ImmutableTuple10 ImmutableTuple11 ImmutableTuple12
|
||||
syn keyword rustTrait ImmutableEqVector ImmutableTotalOrdVector ImmutableCloneableVector
|
||||
syn keyword rustTrait OwnedVector OwnedCloneableVector OwnedEqVector MutableVector
|
||||
syn keyword rustTrait Vector VectorVector CloneableVector ImmutableVector
|
||||
|
|
|
|||
|
|
@ -529,7 +529,7 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: |*c_void| -> T) -> T {
|
|||
let mut tmps = vec::with_capacity(env.len());
|
||||
|
||||
for pair in env.iter() {
|
||||
let kv = format!("{}={}", pair.first(), pair.second());
|
||||
let kv = format!("{}={}", *pair.ref0(), *pair.ref1());
|
||||
tmps.push(kv.to_c_str());
|
||||
}
|
||||
|
||||
|
|
@ -553,7 +553,7 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T {
|
|||
let mut blk = ~[];
|
||||
|
||||
for pair in env.iter() {
|
||||
let kv = format!("{}={}", pair.first(), pair.second());
|
||||
let kv = format!("{}={}", *pair.ref0(), *pair.ref1());
|
||||
blk.push_all(kv.as_bytes());
|
||||
blk.push(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -599,7 +599,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: &ast::Expr,
|
|||
const_eval::const_uint(i) => i as uint,
|
||||
_ => cx.sess.span_bug(count.span, "count must be integral const expression.")
|
||||
};
|
||||
let vs = vec::from_elem(n, const_expr(cx, elem, is_local).first());
|
||||
let vs = vec::from_elem(n, const_expr(cx, elem, is_local).val0());
|
||||
let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
|
||||
C_struct(vs, false)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -4604,7 +4604,7 @@ pub fn determine_inherited_purity(parent: (ast::Purity, ast::NodeId),
|
|||
// purity inferred for it, then check it under its parent's purity.
|
||||
// Otherwise, use its own
|
||||
match child_sigil {
|
||||
ast::BorrowedSigil if child.first() == ast::ImpureFn => parent,
|
||||
ast::BorrowedSigil if child.val0() == ast::ImpureFn => parent,
|
||||
_ => child
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2611,7 +2611,7 @@ mod tests {
|
|||
assert_eq!(vi.size_hint(), (10, Some(10)));
|
||||
|
||||
assert_eq!(c.take(5).size_hint(), (5, Some(5)));
|
||||
assert_eq!(c.skip(5).size_hint().second(), None);
|
||||
assert_eq!(c.skip(5).size_hint().val1(), None);
|
||||
assert_eq!(c.take_while(|_| false).size_hint(), (0, None));
|
||||
assert_eq!(c.skip_while(|_| false).size_hint(), (0, None));
|
||||
assert_eq!(c.enumerate().size_hint(), (uint::MAX, None));
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ pub use io::{Buffer, Writer, Reader, Seek};
|
|||
pub use str::{Str, StrVector, StrSlice, OwnedStr, IntoMaybeOwned};
|
||||
pub use to_bytes::IterBytes;
|
||||
pub use to_str::{ToStr, IntoStr};
|
||||
pub use tuple::{CloneableTuple, ImmutableTuple};
|
||||
pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};
|
||||
pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
|
||||
pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
|
||||
|
|
|
|||
|
|
@ -567,14 +567,14 @@ impl<'a> Iterator<&'a str> for StrSplits<'a> {
|
|||
// Helper functions used for Unicode normalization
|
||||
fn canonical_sort(comb: &mut [(char, u8)]) {
|
||||
use iter::range;
|
||||
use tuple::CloneableTuple;
|
||||
use tuple::Tuple2;
|
||||
|
||||
let len = comb.len();
|
||||
for i in range(0, len) {
|
||||
let mut swapped = false;
|
||||
for j in range(1, len-i) {
|
||||
let classA = comb[j-1].second();
|
||||
let classB = comb[j].second();
|
||||
let classA = *comb[j-1].ref1();
|
||||
let classB = *comb[j].ref1();
|
||||
if classA != 0 && classB != 0 && classA > classB {
|
||||
comb.swap(j-1, j);
|
||||
swapped = true;
|
||||
|
|
|
|||
|
|
@ -19,66 +19,6 @@ use fmt;
|
|||
use result::{Ok, Err};
|
||||
use to_str::ToStr;
|
||||
|
||||
/// Method extensions to pairs where both types satisfy the `Clone` bound
|
||||
pub trait CloneableTuple<T, U> {
|
||||
/// Return the first element of self
|
||||
fn first(&self) -> T;
|
||||
/// Return the second element of self
|
||||
fn second(&self) -> U;
|
||||
/// Return the results of swapping the two elements of self
|
||||
fn swap(&self) -> (U, T);
|
||||
}
|
||||
|
||||
impl<T:Clone,U:Clone> CloneableTuple<T, U> for (T, U) {
|
||||
/// Return the first element of self
|
||||
#[inline]
|
||||
fn first(&self) -> T {
|
||||
match *self {
|
||||
(ref t, _) => (*t).clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the second element of self
|
||||
#[inline]
|
||||
fn second(&self) -> U {
|
||||
match *self {
|
||||
(_, ref u) => (*u).clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the results of swapping the two elements of self
|
||||
#[inline]
|
||||
fn swap(&self) -> (U, T) {
|
||||
match (*self).clone() {
|
||||
(t, u) => (u, t),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Method extensions for pairs where the types don't necessarily satisfy the
|
||||
/// `Clone` bound
|
||||
pub trait ImmutableTuple<T, U> {
|
||||
/// Return a reference to the first element of self
|
||||
fn first_ref<'a>(&'a self) -> &'a T;
|
||||
/// Return a reference to the second element of self
|
||||
fn second_ref<'a>(&'a self) -> &'a U;
|
||||
}
|
||||
|
||||
impl<T, U> ImmutableTuple<T, U> for (T, U) {
|
||||
#[inline]
|
||||
fn first_ref<'a>(&'a self) -> &'a T {
|
||||
match *self {
|
||||
(ref t, _) => t,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn second_ref<'a>(&'a self) -> &'a U {
|
||||
match *self {
|
||||
(_, ref u) => u,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// macro for implementing n-ary tuple functions and operations
|
||||
macro_rules! tuple_impls {
|
||||
($(
|
||||
|
|
@ -339,26 +279,11 @@ mod tests {
|
|||
use clone::Clone;
|
||||
use cmp::*;
|
||||
|
||||
#[test]
|
||||
fn test_tuple_ref() {
|
||||
let x = (~"foo", ~"bar");
|
||||
assert_eq!(x.first_ref(), &~"foo");
|
||||
assert_eq!(x.second_ref(), &~"bar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tuple() {
|
||||
assert_eq!((948, 4039.48).first(), 948);
|
||||
assert_eq!((34.5, ~"foo").second(), ~"foo");
|
||||
assert_eq!(('a', 2).swap(), (2, 'a'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clone() {
|
||||
let a = (1, ~"2");
|
||||
let b = a.clone();
|
||||
assert_eq!(a.first(), b.first());
|
||||
assert_eq!(a.second(), b.second());
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ fn recurse_or_fail(depth: int, st: Option<State>) {
|
|||
State {
|
||||
managed: @Cons((), st.managed),
|
||||
unique: ~Cons((), @*st.unique),
|
||||
tuple: (@Cons((), st.tuple.first()),
|
||||
~Cons((), @*st.tuple.second())),
|
||||
tuple: (@Cons((), st.tuple.ref0().clone()),
|
||||
~Cons((), @*st.tuple.ref1().clone())),
|
||||
vec: st.vec + &[@Cons((), *st.vec.last().unwrap())],
|
||||
res: r(@Cons((), st.res._l))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue