Skip to content

Commit

Permalink
Implement Hash for tuples of up to arity 12. Also change the style to…
Browse files Browse the repository at this point in the history
… be consistent with core::tuple
  • Loading branch information
nham committed Jul 27, 2014
1 parent e0d10bb commit e7b41ca
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/libcollections/hash/mod.rs
Expand Up @@ -155,29 +155,36 @@ macro_rules! impl_hash_tuple(
}
);

($A:ident $($B:ident)*) => (
impl<
S: Writer,
$A: Hash<S> $(, $B: Hash<S>)*
> Hash<S> for ($A, $($B),*) {
( $($name:ident)+) => (
impl<S: Writer, $($name: Hash<S>),*> Hash<S> for ($($name,)*) {
#[allow(uppercase_variables)]
#[inline]
fn hash(&self, state: &mut S) {
match *self {
(ref $A, $(ref $B),*) => {
$A.hash(state);
($(ref $name,)*) => {
$(
$B.hash(state);
$name.hash(state);
)*
}
}
}
}

impl_hash_tuple!($($B)*)
);
)

impl_hash_tuple!(a0 a1 a2 a3 a4 a5 a6 a7)
impl_hash_tuple!()
impl_hash_tuple!(A)
impl_hash_tuple!(A B)
impl_hash_tuple!(A B C)
impl_hash_tuple!(A B C D)
impl_hash_tuple!(A B C D E)
impl_hash_tuple!(A B C D E F)
impl_hash_tuple!(A B C D E F G)
impl_hash_tuple!(A B C D E F G H)
impl_hash_tuple!(A B C D E F G H I)
impl_hash_tuple!(A B C D E F G H I J)
impl_hash_tuple!(A B C D E F G H I J K)
impl_hash_tuple!(A B C D E F G H I J K L)

impl<'a, S: Writer, T: Hash<S>> Hash<S> for &'a [T] {
#[inline]
Expand Down

5 comments on commit e7b41ca

@bors
Copy link
Contributor

@bors bors commented on e7b41ca Jul 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at nham@e7b41ca

@bors
Copy link
Contributor

@bors bors commented on e7b41ca Jul 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nham/rust/hash_tuple_impl = e7b41ca into auto

@bors
Copy link
Contributor

@bors bors commented on e7b41ca Jul 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nham/rust/hash_tuple_impl = e7b41ca merged ok, testing candidate = f653d9f

@bors
Copy link
Contributor

@bors bors commented on e7b41ca Jul 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = f653d9f

Please sign in to comment.