Skip to content

Commit

Permalink
Add static assertions to ensure Quantity implements appropriate marke…
Browse files Browse the repository at this point in the history
…r traits.

Assert that Quantity implements `Clone`, `Copy`, `Send`, `Sync`, and
`hash::Hash` as appropriate based on the underlying storage type.

Closes #29.
  • Loading branch information
iliekturtles committed Dec 21, 2017
1 parent c48171d commit 662fb77
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ num = "0.1"
typenum = "1.9.0"

[dev-dependencies]
quickcheck = "0.5.0"
approx = "0.1.1"
quickcheck = "0.5.0"
static_assertions = "0.2.5"

[features]
default = ["f32", "f64", "si", "std"]
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ extern crate approx;
#[cfg(test)]
#[macro_use]
extern crate quickcheck;
#[cfg(test)]
#[macro_use]
extern crate static_assertions;

// Conditionally import `core` or `std` based on feature selection.
#[doc(hidden)]
Expand Down
32 changes: 32 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,3 +998,35 @@ mod quantities_macro {
}
}
}

mod static_checks {
storage_types! {
types: Float;

use tests::*;

assert_impl!(q; Quantity<Q<Z0, Z0>, U<V>, V>, Clone, Copy, Send, Sync);
}

storage_types! {
types: PrimInt, Rational, Rational32, Rational64;

use tests::*;

#[cfg(feature = "std")]
assert_impl!(q; Quantity<Q<Z0, Z0>, U<V>, V>, Clone, Copy, Send, Sync, ::lib::hash::Hash);
#[cfg(not(feature = "std"))]
assert_impl!(q; Quantity<Q<Z0, Z0>, U<V>, V>, Clone, Copy, Send, Sync, ::lib::hash::Hash);
}

storage_types! {
types: BigInt, BigUint, BigRational;

use tests::*;

#[cfg(feature = "std")]
assert_impl!(q; Quantity<Q<Z0, Z0>, U<V>, V>, Clone, Send, Sync, ::lib::hash::Hash);
#[cfg(not(feature = "std"))]
assert_impl!(q; Quantity<Q<Z0, Z0>, U<V>, V>, Clone, Send, Sync, ::lib::hash::Hash);
}
}

0 comments on commit 662fb77

Please sign in to comment.