Skip to content

Commit 73fdacb

Browse files
author
blake2-ppc
committed
std::to_bytes: Implement IterBytes on 1- to 8-tuples
1 parent 6066118 commit 73fdacb

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

src/libstd/to_bytes.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,29 +235,38 @@ impl<'self,A:IterBytes> IterBytes for &'self [A] {
235235
}
236236
}
237237

238-
impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) {
239-
#[inline]
240-
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
241-
match *self {
242-
(ref a, ref b) => { a.iter_bytes(lsb0, |b| f(b)) &&
243-
b.iter_bytes(lsb0, |b| f(b)) }
244-
}
245-
}
246-
}
247-
248-
impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) {
249-
#[inline]
250-
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
251-
match *self {
252-
(ref a, ref b, ref c) => {
253-
a.iter_bytes(lsb0, |b| f(b)) &&
254-
b.iter_bytes(lsb0, |b| f(b)) &&
255-
c.iter_bytes(lsb0, |b| f(b))
256-
}
238+
impl<A: IterBytes> IterBytes for (A, ) {
239+
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
240+
match *self {
241+
(ref a, ) => a.iter_bytes(lsb0, |b| f(b))
242+
}
257243
}
258-
}
259244
}
260245

246+
macro_rules! iter_bytes_tuple(
247+
($($A:ident),+) => (
248+
impl<$($A: IterBytes),+> IterBytes for ($($A),+) {
249+
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
250+
match *self {
251+
($(ref $A),+) => {
252+
$(
253+
$A .iter_bytes(lsb0, |b| f(b))
254+
)&&+
255+
}
256+
}
257+
}
258+
}
259+
)
260+
)
261+
262+
iter_bytes_tuple!(A, B)
263+
iter_bytes_tuple!(A, B, C)
264+
iter_bytes_tuple!(A, B, C, D)
265+
iter_bytes_tuple!(A, B, C, D, E)
266+
iter_bytes_tuple!(A, B, C, D, E, F)
267+
iter_bytes_tuple!(A, B, C, D, E, F, G)
268+
iter_bytes_tuple!(A, B, C, D, E, F, G, H)
269+
261270
impl<A:IterBytes> IterBytes for ~[A] {
262271
#[inline]
263272
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {

0 commit comments

Comments
 (0)