Skip to content

Commit

Permalink
Merge pull request serde-rs#89 from joshtriplett/bounded-tuples
Browse files Browse the repository at this point in the history
traits.rs: Implement Bounded for tuples of Bounded types
  • Loading branch information
alexcrichton committed Apr 27, 2015
2 parents 63d2e79 + 6f2db9b commit a3d9093
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,36 @@ bounded_impl!(i64, i64::MIN, i64::MAX);
bounded_impl!(f32, f32::MIN, f32::MAX);
bounded_impl!(f64, f64::MIN, f64::MAX);

macro_rules! for_each_tuple_ {
( $m:ident !! ) => (
$m! { }
);
( $m:ident !! $h:ident, $($t:ident,)* ) => (
$m! { $h $($t)* }
for_each_tuple_! { $m !! $($t,)* }
);
}
macro_rules! for_each_tuple {
( $m:ident ) => (
for_each_tuple_! { $m !! A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, }
);
}

macro_rules! bounded_tuple {
( $($name:ident)* ) => (
impl<$($name: Bounded,)*> Bounded for ($($name,)*) {
fn min_value() -> Self {
($($name::min_value(),)*)
}
fn max_value() -> Self {
($($name::max_value(),)*)
}
}
);
}

for_each_tuple!(bounded_tuple);

/// Saturating math operations
pub trait Saturating {
/// Saturating addition operator.
Expand Down

0 comments on commit a3d9093

Please sign in to comment.