~jplatte/const-unit-poc

c62d53fca1f5393796fc945b103390b5b432c2bc — Jonas Platte 7 months ago 4d28d54
Add some scaled values
3 files changed, 28 insertions(+), 5 deletions(-)

M examples/shouldwork.rs
M src/lib.rs
M src/values.rs
M examples/shouldwork.rs => examples/shouldwork.rs +2 -2
@@ 1,7 1,7 @@
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]

use const_unit_poc::values::{kg, m, s, N};
use const_unit_poc::values::{cm, kg, m, s, N};

fn main() {
    let distance = 1.0 * m;


@@ 10,7 10,7 @@ fn main() {
    assert_eq!(force, 5.0 * N);

    let mut mutable_distance = 3.2 * m;
    mutable_distance -= 0.2 * m;
    mutable_distance -= 20.0 * cm;
    mutable_distance += 2.0 * m;

    assert_eq!(mutable_distance, 5.0 * m);

M src/lib.rs => src/lib.rs +2 -2
@@ 6,7 6,7 @@
//!
//! ```
//! #![feature(const_generics, const_evaluatable_checked)]
//! use const_unit_poc::values::{m, kg, s, N};
//! use const_unit_poc::values::{cm, kg, m, s, N};
//!
//! let distance = 1.0 * m;
//! let mass = 18.0 * kg;


@@ 14,7 14,7 @@
//! assert_eq!(force, 5.0 * N);
//!
//! let mut mutable_distance = 3.2 * m;
//! mutable_distance -= 0.2 * m;
//! mutable_distance -= 20.0 * cm;
//! mutable_distance += 2.0 * m;
//!
//! assert_eq!(mutable_distance, 5.0 * m);

M src/values.rs => src/values.rs +24 -1
@@ 25,7 25,30 @@ pub const mol: Quantity<{ units::mol }> = Quantity { raw_value: 1.0 };
/// 1 candela
pub const cd: Quantity<{ units::cd }> = Quantity { raw_value: 1.0 };

// derived
// random selection of scaled values

/// 1 centimeter
pub const cm: Quantity<{ units::m }> = Quantity { raw_value: 0.01 };

/// 1 millimeter
pub const mm: Quantity<{ units::m }> = Quantity { raw_value: 0.001 };

/// 1 kilomet
pub const km: Quantity<{ units::m }> = Quantity { raw_value: 1000.0 };

/// 1 gram
pub const g: Quantity<{ units::kg }> = Quantity { raw_value: 0.001 };

/// 1 millisecond
pub const ms: Quantity<{ units::s }> = Quantity { raw_value: 0.001 };

/// 1 minute
pub const min: Quantity<{ units::s }> = Quantity { raw_value: 60.0 };

/// 1 hour
pub const h: Quantity<{ units::s }> = Quantity { raw_value: 3600.0 };

// random selection of derived values

/// 1 newton
pub const N: Quantity<{ units::N }> = Quantity { raw_value: 1.0 };