Make the interface more Newtype like
This commit is contained in:
parent
4c73f860d3
commit
745dcac6bf
21
src/lib.rs
21
src/lib.rs
@ -31,15 +31,13 @@ where
|
||||
Candela: Integer,
|
||||
{
|
||||
value: T,
|
||||
_s: PhantomData<Second>,
|
||||
_m: PhantomData<Metre>,
|
||||
_kg: PhantomData<Kilogram>,
|
||||
_a: PhantomData<Ampere>,
|
||||
_k: PhantomData<Kelvin>,
|
||||
_mol: PhantomData<Mole>,
|
||||
_cd: PhantomData<Candela>,
|
||||
_marker: PhantomData<(Second, Metre, Kilogram, Ampere, Kelvin, Mole, Candela)>,
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn SiUnit<T, Second, Metre, Kilogram, Ampere, Kelvin, Mole, Candela>(
|
||||
value: T,
|
||||
) -> SiUnit<T, Second, Metre, Kilogram, Ampere, Kelvin, Mole, Candela>
|
||||
where
|
||||
Second: Integer,
|
||||
Metre: Integer,
|
||||
@ -49,6 +47,7 @@ where
|
||||
Mole: Integer,
|
||||
Candela: Integer,
|
||||
{
|
||||
SiUnit::new(value)
|
||||
}
|
||||
|
||||
impl<T, Second, Metre, Kilogram, Ampere, Kelvin, Mole, Candela> Deref
|
||||
@ -609,13 +608,7 @@ where
|
||||
pub const fn new(value: T) -> Self {
|
||||
Self {
|
||||
value,
|
||||
_s: PhantomData,
|
||||
_m: PhantomData,
|
||||
_kg: PhantomData,
|
||||
_a: PhantomData,
|
||||
_k: PhantomData,
|
||||
_mol: PhantomData,
|
||||
_cd: PhantomData,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
src/types.rs
22
src/types.rs
@ -1,10 +1,26 @@
|
||||
use crate::SiUnit;
|
||||
use typenum::consts::{N1, N2, N3, P1, P2, P3, P4, Z0};
|
||||
|
||||
macro_rules! unit {
|
||||
($acronym: ident -> $second: ty, $metre: ty, $kilogram: ty, $ampere: ty, $kelvin: ty, $mole: ty, $candela: ty $(; $doc: literal)?) => {
|
||||
$(
|
||||
#[doc = $doc]
|
||||
)?
|
||||
pub type $acronym<T> = SiUnit<T, $second, $metre, $kilogram, $ampere, $kelvin, $mole, $candela>;
|
||||
#[allow(non_snake_case)]
|
||||
$(
|
||||
#[doc = $doc]
|
||||
)?
|
||||
pub const fn $acronym<T>(value: T) -> $acronym<T> {
|
||||
$acronym::new(value)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Base units
|
||||
pub type Unit<T> = SiUnit<T, Z0, Z0, Z0, Z0, Z0, Z0, Z0>;
|
||||
/// time
|
||||
pub type Second<T> = SiUnit<T, P1, Z0, Z0, Z0, Z0, Z0, Z0>;
|
||||
unit!(Unit -> Z0, Z0, Z0, Z0, Z0, Z0, Z0);
|
||||
unit!(Second -> P1, Z0, Z0, Z0, Z0, Z0, Z0; "time");
|
||||
//pub type Second<T> = SiUnit<T, P1, Z0, Z0, Z0, Z0, Z0, Z0>;
|
||||
/// length
|
||||
pub type Metre<T> = SiUnit<T, Z0, P1, Z0, Z0, Z0, Z0, Z0>;
|
||||
/// mass
|
||||
|
Loading…
Reference in New Issue
Block a user