Skip to content

Commit

Permalink
Assert Unpin for all relevant types and storage types
Browse files Browse the repository at this point in the history
New `impl`s added for `Arguments<D, N>` and
`QuantityArguments<D, U, V, N>`.
  • Loading branch information
iliekturtles committed Oct 5, 2020
1 parent de81778 commit 1a3386a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
18 changes: 17 additions & 1 deletion src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ macro_rules! system {
where
D: Dimension + ?Sized,
U: Units<V> + ?Sized,
V: $crate::num::Num + $crate::Conversion<V> + Unpin,
V: $crate::num::Num + $crate::Conversion<V> + $crate::lib::marker::Unpin,
{
}

Expand Down Expand Up @@ -1417,6 +1417,13 @@ macro_rules! system {
{
}

impl<D, N> $crate::lib::marker::Unpin for Arguments<D, N>
where
D: Dimension + ?Sized,
N: Unit + $crate::lib::marker::Unpin,
{
}

impl<D, U, V, N> $crate::lib::clone::Clone for QuantityArguments<D, U, V, N>
where
D: Dimension + ?Sized,
Expand All @@ -1441,6 +1448,15 @@ macro_rules! system {
{
}

impl<D, U, V, N> $crate::lib::marker::Unpin for QuantityArguments<D, U, V, N>
where
D: Dimension + ?Sized,
U: Units<V> + ?Sized,
V: $crate::num::Num + $crate::Conversion<V> + $crate::lib::marker::Unpin,
N: Unit + $crate::lib::marker::Unpin,
{
}

macro_rules! format_arguments {
($style:ident) => {
impl<D, U, V, N> fmt::$style for QuantityArguments<D, U, V, N>
Expand Down
32 changes: 17 additions & 15 deletions src/tests/asserts.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Static assertions.
use crate::lib::fmt::{Binary, Debug, Display, LowerExp, LowerHex, Octal, UpperExp, UpperHex};
use crate::lib::marker::Unpin;
use crate::tests::*;

assert_impl_all!(Arguments<Q<Z0, Z0, Z0>, meter>: Clone, Copy);
assert_impl_all!(Arguments<Q<Z0, Z0, Z0>, meter>: Clone, Copy, Unpin);
assert_not_impl_any!(Arguments<Q<Z0, Z0, Z0>, meter>: Binary, Debug, Display, LowerExp, LowerHex,
Octal, UpperExp, UpperHex);
assert_impl_all!(DisplayStyle: Clone, Copy);
Expand All @@ -14,9 +15,9 @@ storage_types! {
use super::*;

assert_impl_all!(Quantity<Q<Z0, Z0, Z0>, U<V>, V>: Clone, Copy, PartialEq, PartialOrd, Send,
Sync);
Sync, Unpin);
assert_impl_all!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: Clone, Copy, Debug, Display,
LowerExp, UpperExp);
LowerExp, Unpin, UpperExp);
assert_not_impl_any!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: Binary, LowerHex, Octal,
UpperHex);
}
Expand All @@ -26,10 +27,10 @@ storage_types! {

use super::*;

assert_impl_all!(Quantity<Q<Z0, Z0, Z0>, U<V>, V>: Clone, Copy, Eq, Ord, PartialEq, PartialOrd,
Send, Sync, crate::lib::hash::Hash);
assert_impl_all!(Quantity<Q<Z0, Z0, Z0>, U<V>, V>: Clone, Copy, Eq, Hash, Ord, PartialEq,
PartialOrd, Send, Sync, Unpin);
assert_impl_all!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: Clone, Copy, Binary, Debug,
Display, LowerHex, Octal, UpperHex);
Display, LowerHex, Octal, Unpin, UpperHex);
assert_not_impl_any!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: LowerExp, UpperExp);
}

Expand All @@ -38,9 +39,10 @@ storage_types! {

use super::*;

assert_impl_all!(Quantity<Q<Z0, Z0, Z0>, U<V>, V>: Clone, Copy, Eq, Ord, PartialEq, PartialOrd,
Send, Sync, crate::lib::hash::Hash);
assert_impl_all!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: Clone, Copy, Debug, Display);
assert_impl_all!(Quantity<Q<Z0, Z0, Z0>, U<V>, V>: Clone, Copy, Eq, Hash, Ord, PartialEq,
PartialOrd, Send, Sync, Unpin);
assert_impl_all!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: Clone, Copy, Debug, Display,
Unpin);
assert_not_impl_any!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: Binary, LowerExp,
LowerHex, Octal, UpperExp, UpperHex);
}
Expand All @@ -50,10 +52,10 @@ storage_types! {

use super::*;

assert_impl_all!(Quantity<Q<Z0, Z0, Z0>, U<V>, V>: Clone, Eq, Ord, PartialEq, PartialOrd, Send,
Sync, crate::lib::hash::Hash);
assert_impl_all!(Quantity<Q<Z0, Z0, Z0>, U<V>, V>: Clone, Eq, Hash, Ord, PartialEq, PartialOrd,
Send, Sync, Unpin);
assert_impl_all!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: Clone, Binary, Debug,
Display, LowerHex, Octal, UpperHex);
Display, LowerHex, Octal, Unpin, UpperHex);
assert_not_impl_any!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: LowerExp, UpperExp);
}

Expand All @@ -62,9 +64,9 @@ storage_types! {

use super::*;

assert_impl_all!(Quantity<Q<Z0, Z0, Z0>, U<V>, V>: Clone, Eq, Ord, PartialEq, PartialOrd, Send,
Sync, crate::lib::hash::Hash);
assert_impl_all!(Quantity<Q<Z0, Z0, Z0>, U<V>, V>: Clone, Eq, Hash, Ord, PartialEq, PartialOrd,
Send, Sync, Unpin);
assert_impl_all!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: Clone, Debug, Display);
assert_not_impl_any!(QuantityArguments<Q<Z0, Z0, Z0>, U<V>, V, meter>: Binary, LowerExp,
LowerHex, Octal, UpperExp, UpperHex);
LowerHex, Octal, UpperExp, Unpin, UpperHex);
}
9 changes: 0 additions & 9 deletions src/tests/quantities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,6 @@ storage_types! {
&<degree_fahrenheit as Conversion<V>>::constant(ConstantOp::Add).value());
}

#[test]
fn all_quantity_types_are_unpin() {
fn assert_unpin<T: Unpin>() {}

assert_unpin::<Length>();
assert_unpin::<Mass>();
assert_unpin::<ThermodynamicTemperature>();
}

#[cfg(feature = "std")]
#[test]
fn debug_fmt() {
Expand Down

0 comments on commit 1a3386a

Please sign in to comment.