diff options
| author | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-02-16 18:27:46 +1100 |
|---|---|---|
| committer | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-02-16 19:12:28 +1100 |
| commit | 6f39eb1a568c03534a41f6815e7fb0bde737cd6f (patch) | |
| tree | 0b8690f784917b218ed18f82b4f4b7b67b3d62a7 /src | |
| parent | bf6abf8cb3d1e169c1baab8d266bd43c58dfbcc6 (diff) | |
Delegate ToStr implementation to Show for tuples
Diffstat (limited to 'src')
| -rw-r--r-- | src/libstd/to_str.rs | 48 | ||||
| -rw-r--r-- | src/libstd/tuple.rs | 7 |
2 files changed, 7 insertions, 48 deletions
diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index 87d59f09791..ab14e9f5667 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -40,17 +40,6 @@ impl ToStr for () { fn to_str(&self) -> ~str { ~"()" } } -impl<A:ToStr> ToStr for (A,) { - #[inline] - fn to_str(&self) -> ~str { - match *self { - (ref a,) => { - format!("({},)", (*a).to_str()) - } - } - } -} - impl<A:ToStr+Hash+Eq, B:ToStr> ToStr for HashMap<A, B> { #[inline] fn to_str(&self) -> ~str { @@ -91,36 +80,6 @@ impl<A:ToStr+Hash+Eq> ToStr for HashSet<A> { } } -impl<A:ToStr,B:ToStr> ToStr for (A, B) { - #[inline] - fn to_str(&self) -> ~str { - // FIXME(#4653): this causes an llvm assertion - //let &(ref a, ref b) = self; - match *self { - (ref a, ref b) => { - format!("({}, {})", (*a).to_str(), (*b).to_str()) - } - } - } -} - -impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) { - #[inline] - fn to_str(&self) -> ~str { - // FIXME(#4653): this causes an llvm assertion - //let &(ref a, ref b, ref c) = self; - match *self { - (ref a, ref b, ref c) => { - format!("({}, {}, {})", - (*a).to_str(), - (*b).to_str(), - (*c).to_str() - ) - } - } - } -} - impl<'a,A:ToStr> ToStr for &'a [A] { #[inline] fn to_str(&self) -> ~str { @@ -179,13 +138,6 @@ mod tests { } #[test] - fn test_tuple_types() { - assert_eq!((1, 2).to_str(), ~"(1, 2)"); - assert_eq!((~"a", ~"b", false).to_str(), ~"(a, b, false)"); - assert_eq!(((), ((), 100)).to_str(), ~"((), ((), 100))"); - } - - #[test] fn test_vectors() { let x: ~[int] = ~[]; assert_eq!(x.to_str(), ~"[]"); diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 9a1fda07ecd..f2d1144f281 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -17,6 +17,7 @@ use clone::Clone; #[cfg(not(test))] use default::Default; 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> { @@ -179,6 +180,12 @@ macro_rules! tuple_impls { } } + impl<$($T: fmt::Show),+> ToStr for ($($T,)+) { + fn to_str(&self) -> ~str { + format!("{}", *self) + } + } + impl<$($T: fmt::Show),+> fmt::Show for ($($T,)+) { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write_tuple!(f.buf, $(self.$get_ref_fn()),+) |
