small API change: Measurement no longer takes a unit in new
parent
292f61d582
commit
5031157fea
|
@ -1,4 +1,4 @@
|
|||
[package]
|
||||
name = "unidades"
|
||||
version = "1.1.3"
|
||||
version = "1.2.0"
|
||||
edition = "2021"
|
||||
|
|
|
@ -28,10 +28,8 @@ impl<
|
|||
const AMOUNT: i8,
|
||||
const INTENSITY: i8,
|
||||
> Measurement<TIME, LENGTH, MASS, CURRENT, TEMPERATURE, AMOUNT, INTENSITY> {
|
||||
pub fn new<U>(v: f64) -> Self
|
||||
where
|
||||
U: Unit<Self> {
|
||||
Self(v.mul(U::scale()).add(U::offset()))
|
||||
pub fn new(v: f64) -> Self {
|
||||
Self(v)
|
||||
}
|
||||
|
||||
pub fn to_units<U>(self) -> f64
|
||||
|
|
|
@ -49,8 +49,6 @@ macro_rules! prefix_group{
|
|||
};
|
||||
}
|
||||
|
||||
pub use prefix_group;
|
||||
|
||||
prefix_group!{
|
||||
(Quetta, 1e30),
|
||||
(Ronna, 1e27),
|
||||
|
|
19
src/units.rs
19
src/units.rs
|
@ -2,6 +2,7 @@ use crate::{
|
|||
Unit,
|
||||
dimensions::*,
|
||||
};
|
||||
use core::ops::{Mul, Add};
|
||||
|
||||
const YEAR: f64 = 31_557_600.0;
|
||||
const DAY: f64 = 60.0 * 60.0 * 24.0;
|
||||
|
@ -11,7 +12,7 @@ macro_rules! unit{
|
|||
($dimension: ident => $(($nym: ident, ($scale: expr, $offset: expr))), *) => {
|
||||
$(pub struct $nym; impl Unit < $dimension > for $nym {
|
||||
fn new(v: f64) -> $dimension {
|
||||
$dimension:: new::< Self >(v)
|
||||
$dimension:: new(v.mul(Self::scale()).add(Self::offset()))
|
||||
}
|
||||
fn scale() -> f64 {
|
||||
$scale
|
||||
|
@ -23,22 +24,6 @@ macro_rules! unit{
|
|||
};
|
||||
}
|
||||
|
||||
pub use unit;
|
||||
|
||||
impl Unit<Scalar> for () {
|
||||
fn new(v: f64) -> Scalar {
|
||||
Scalar::new::<()>(v)
|
||||
}
|
||||
|
||||
fn scale() -> f64 {
|
||||
1.0
|
||||
}
|
||||
|
||||
fn offset() -> f64 {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
|
||||
unit!{
|
||||
Time =>(Second, (1.0, 0.0)),
|
||||
(Kalpa, (YEAR * 1e9 * 4.32, 0.0)),
|
||||
|
|
Loading…
Reference in New Issue