Remove requirement for derive_more attributes to be in scope when using quantity_type!
This commit is contained in:
@ -30,11 +30,11 @@ impl Parse for QuantityInput {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Remove requirement for physical::quantity::{Quantity, Value}
|
||||
/// The following imports must be in scope for this macro to work
|
||||
/// ```
|
||||
/// use physical::quantity::{Quantity, Value};
|
||||
/// use derive_more::{Add, AddAssign, Display, Sub, SubAssign};
|
||||
/// use generate_quantity::quantity_type;
|
||||
/// use physical::quantity::{Quantity, Value};
|
||||
/// ```
|
||||
#[proc_macro]
|
||||
pub fn quantity_type(input: TokenStream) -> TokenStream {
|
||||
@ -98,7 +98,17 @@ pub fn quantity_type(input: TokenStream) -> TokenStream {
|
||||
|
||||
//----- Output Code ----------------------------------
|
||||
let expanded = quote! {
|
||||
#[derive(Copy, Clone, PartialEq, PartialOrd, Add, AddAssign, Sub, SubAssign, Display)]
|
||||
#[derive(
|
||||
Copy,
|
||||
Clone,
|
||||
PartialEq,
|
||||
PartialOrd,
|
||||
derive_more::Add,
|
||||
derive_more::AddAssign,
|
||||
derive_more::Sub,
|
||||
derive_more::SubAssign,
|
||||
derive_more::Display
|
||||
)]
|
||||
#[display(fmt = "{} {}", _0, "Self::symbol()")]
|
||||
#[repr(transparent)]
|
||||
pub struct #struct_name<V: Value>(pub V);
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::quantity::{Quantity, Value};
|
||||
use derive_more::{Add, AddAssign, Display, Sub, SubAssign};
|
||||
use generate_quantity::quantity_type;
|
||||
|
||||
//----- Watter per Square Meter ----------------------------------
|
||||
|
@ -1,4 +1,3 @@
|
||||
use derive_more::{Add, AddAssign, Display, Sub, SubAssign};
|
||||
use generate_quantity::quantity_type;
|
||||
use crate::quantity::{Quantity, Value};
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
use derive_more::{Add, AddAssign, Display, Sub, SubAssign};
|
||||
use generate_quantity::quantity_type;
|
||||
use crate::quantity::{DECI, Quantity, Value};
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
use derive_more::{Add, AddAssign, Display, Sub, SubAssign};
|
||||
use generate_quantity::quantity_type;
|
||||
use crate::quantity::{Quantity, Value};
|
||||
|
||||
@ -32,22 +31,22 @@ impl<V: Value> MilliVolts<V> {
|
||||
mod tests {
|
||||
use float_cmp::assert_approx_eq;
|
||||
use super::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn convert_u32() {
|
||||
let volts: Volts<u32> = 3.volts();
|
||||
let millivolts: MilliVolts<u32> = 3_000.milli_volts();
|
||||
|
||||
|
||||
assert_eq!(volts.to_millivolts().0, millivolts.0);
|
||||
assert_eq!(millivolts.to_volts().0, volts.0);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn convert_f64() {
|
||||
let volts: Volts<f64> = 3.0.volts();
|
||||
let millivolts: MilliVolts<f64> = 3_000.0.milli_volts();
|
||||
|
||||
|
||||
assert_approx_eq!(f64, volts.to_millivolts().0, millivolts.0);
|
||||
assert_approx_eq!(f64, millivolts.to_volts().0, volts.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::quantity::{Quantity, Value};
|
||||
use derive_more::{Add, AddAssign, Display, Sub, SubAssign};
|
||||
use generate_quantity::quantity_type;
|
||||
|
||||
//----- Liters per Minute ----------------------------------
|
||||
|
Reference in New Issue
Block a user