diff options
| author | blake2-ppc <blake2-ppc> | 2013-08-15 23:51:39 +0200 | 
|---|---|---|
| committer | blake2-ppc <blake2-ppc> | 2013-08-18 18:39:47 +0200 | 
| commit | 73fdacbac98b2a820684556fc8245148af3a9247 (patch) | |
| tree | 2c6184032073ef7c3aca9f3e20624548a6e22717 /src/libstd/to_bytes.rs | |
| parent | 6066118b2988fee1b758d542cee18ffe7a84acab (diff) | |
| download | rust-73fdacbac98b2a820684556fc8245148af3a9247.tar.gz rust-73fdacbac98b2a820684556fc8245148af3a9247.zip | |
std::to_bytes: Implement IterBytes on 1- to 8-tuples
Diffstat (limited to 'src/libstd/to_bytes.rs')
| -rw-r--r-- | src/libstd/to_bytes.rs | 49 | 
1 files changed, 29 insertions, 20 deletions
| diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index a831c97438a..198c09964bb 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -235,29 +235,38 @@ impl<'self,A:IterBytes> IterBytes for &'self [A] { } } -impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) { - #[inline] - fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { - match *self { - (ref a, ref b) => { a.iter_bytes(lsb0, |b| f(b)) && - b.iter_bytes(lsb0, |b| f(b)) } - } - } -} - -impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) { - #[inline] - fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { - match *self { - (ref a, ref b, ref c) => { - a.iter_bytes(lsb0, |b| f(b)) && - b.iter_bytes(lsb0, |b| f(b)) && - c.iter_bytes(lsb0, |b| f(b)) - } +impl<A: IterBytes> IterBytes for (A, ) { + fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { + match *self { + (ref a, ) => a.iter_bytes(lsb0, |b| f(b)) + } } - } } +macro_rules! iter_bytes_tuple( + ($($A:ident),+) => ( + impl<$($A: IterBytes),+> IterBytes for ($($A),+) { + fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { + match *self { + ($(ref $A),+) => { + $( + $A .iter_bytes(lsb0, |b| f(b)) + )&&+ + } + } + } + } + ) +) + +iter_bytes_tuple!(A, B) +iter_bytes_tuple!(A, B, C) +iter_bytes_tuple!(A, B, C, D) +iter_bytes_tuple!(A, B, C, D, E) +iter_bytes_tuple!(A, B, C, D, E, F) +iter_bytes_tuple!(A, B, C, D, E, F, G) +iter_bytes_tuple!(A, B, C, D, E, F, G, H) + impl<A:IterBytes> IterBytes for ~[A] { #[inline] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { | 
