unitscale 0.2.0

Facade crate for statically-scaled unit macros and traits.
Documentation
// Copyright 2025 GooseGrid Technologies
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![doc = include_str!("../README.md")]

/// Core traits and types (e.g., `UnitScale`, `Scaled`)
pub mod core {
    pub use unitscale_core::*;
}

/// Procedural macros (`unit_data`, `unit_scale`)
pub mod macros {
    pub use unitscale_macros::*;
}

/// SI `UnitScale` prefixes for convenience
pub mod si;

/// Common imports for users
pub mod prelude {
    pub use crate::core::{
        Scaled, ScaledPrimitiveByteSize, UnitScaleError, UnitScaleF32, UnitScaleF64,
    };
    pub use crate::macros::{unit_scale, unit_type};
}

#[cfg(test)]
mod tests {
    use crate::prelude::*;

    use crate::si::f32::Hecto;
    use crate::si::f64::Hecto as HectoF64;

    #[unit_scale(to = 0.5)]
    struct Scale0_5;

    #[unit_scale(to = 0.5, with = "f64")]
    struct Scale0_5F64;

    #[unit_type]
    struct DataType;

    #[unit_type(with = "f64")]
    struct DataTypeF64;

    #[test]
    fn f32_macro_test() {
        let half_data: DataType<Scale0_5, u16> =
            DataType::try_from(100.0).expect("Unable to convert");
        let result: u16 = 200;

        assert_eq!(half_data.scaled_value(), result);
    }

    #[test]
    fn f64_macro_test() {
        let half_data: DataTypeF64<Scale0_5F64, u16> =
            DataTypeF64::try_from(100.0).expect("Unable to convert");
        let result: u16 = 200;

        assert_eq!(half_data.scaled_value(), result);
    }

    #[test]
    fn si_scalars() {
        let hundredth_data: DataType<Hecto, u16> =
            DataType::try_from(100.0).expect("Unable to convert");
        let result: u16 = 1;

        assert_eq!(hundredth_data.scaled_value(), result);

        let hundredth_data: DataTypeF64<HectoF64, u16> =
            DataTypeF64::try_from(100.0).expect("Unable to convert");

        assert_eq!(hundredth_data.scaled_value(), result);
    }
}