asklyphe/unit_converter/src/unit_defs.rs

50 lines
1.3 KiB
Rust
Raw Normal View History

2025-03-12 12:32:15 -07:00
/*
* unit_converter length_units.rs
* - generic stuff for all units
*
* Copyright (C) 2025 Real Microsoft, LLC
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::length_units::LengthUnit;
use astro_float::BigFloat;
pub trait ConvertTo<B> {
fn convert_to(self, value: BigFloat, into: B) -> BigFloat;
}
pub trait BestUnit {
fn best_unit(self, value: BigFloat) -> Self;
}
pub trait UnitName {
fn unit_name(self, value: BigFloat) -> String;
}
pub trait FromUnitName<T: Sized> {
fn parse(value: String) -> Option<(T, String)>;
}
pub enum Unit {
Length(LengthUnit),
}
#[derive(Ord, PartialOrd, Eq, PartialEq, Copy, Clone, Debug)]
pub enum MetricPrefix {
Pico,
Nano,
Micro,
Milli,
Centi,
Deci,
None,
Deca,
Hecto,
Kilo,
Mega,
Giga,
Tera,
}