core: Inherit the tuple module

This commit is contained in:
Alex Crichton 2014-04-30 21:02:13 -07:00
parent 1a989d6769
commit 92095d125a
4 changed files with 32 additions and 21 deletions

View File

@ -44,3 +44,4 @@ pub mod any;
pub mod finally;
pub mod raw;
pub mod char;
pub mod tuple;

View File

@ -15,8 +15,6 @@
use clone::Clone;
#[cfg(not(test))] use cmp::*;
#[cfg(not(test))] use default::Default;
use fmt;
use result::{Ok, Err};
// macro for implementing n-ary tuple functions and operations
macro_rules! tuple_impls {
@ -112,12 +110,6 @@ macro_rules! tuple_impls {
($({ let x: $T = Default::default(); x},)+)
}
}
impl<$($T: fmt::Show),+> fmt::Show for ($($T,)+) {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write_tuple!(f.buf, $(self.$refN()),+)
}
}
)+
}
}
@ -144,18 +136,6 @@ macro_rules! lexical_cmp {
($a:expr, $b:expr) => { ($a).cmp($b) };
}
macro_rules! write_tuple {
($buf:expr, $x:expr) => (
write!($buf, "({},)", *$x)
);
($buf:expr, $hd:expr, $($tl:expr),+) => ({
try!(write!($buf, "("));
try!(write!($buf, "{}", *$hd));
$(try!(write!($buf, ", {}", *$tl));)+
write!($buf, ")")
});
}
tuple_impls! {
Tuple1 {
(val0, ref0, mut0) -> A { (a) => a }

View File

@ -1242,6 +1242,36 @@ impl<T> Show for *mut T {
fn fmt(&self, f: &mut Formatter) -> Result { secret_pointer(self, f) }
}
macro_rules! peel(($name:ident, $($other:ident,)*) => (tuple!($($other,)*)))
macro_rules! tuple (
() => ();
( $($name:ident,)+ ) => (
impl<$($name:Show),*> Show for ($($name,)*) {
#[allow(uppercase_variables, dead_assignment)]
fn fmt(&self, f: &mut Formatter) -> Result {
try!(write!(f.buf, "("));
let ($(ref $name,)*) = *self;
let mut n = 0;
$(
if n > 0 {
try!(write!(f.buf, ", "));
}
try!(write!(f.buf, "{}", *$name));
n += 1;
)*
if n == 1 {
try!(write!(f.buf, ","));
}
write!(f.buf, ")")
}
}
peel!($($name,)*)
)
)
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
impl Show for Box<any::Any> {
fn fmt(&self, f: &mut Formatter) -> Result { f.pad("Box<Any>") }
}

View File

@ -147,6 +147,7 @@ pub use core::intrinsics;
pub use core::mem;
pub use core::ptr;
pub use core::raw;
pub use core::tuple;
// Run tests with libgreen instead of libnative.
//
@ -192,7 +193,6 @@ pub mod prelude;
#[path = "num/f64.rs"] pub mod f64;
pub mod bool;
pub mod tuple;
pub mod slice;
pub mod vec;