pub mod moles {
pub fn to_millimoles(value: f64) -> f64 {
value * 1000.0
}
pub fn to_micromoles(value: f64) -> f64 {
value * 1_000_000.0
}
pub fn to_nanomoles(value: f64) -> f64 {
value * 1_000_000_000.0
}
pub fn to_picomoles(value: f64) -> f64 {
value * 1_000_000_000_000.0
}
pub fn to_kilomoles(value: f64) -> f64 {
value / 1000.0
}
}
pub mod millimoles {
pub fn to_moles(value: f64) -> f64 {
value / 1000.0
}
pub fn to_micromoles(value: f64) -> f64 {
value * 1000.0
}
pub fn to_nanomoles(value: f64) -> f64 {
value * 1_000_000.0
}
pub fn to_picomoles(value: f64) -> f64 {
value * 1_000_000_000.0
}
pub fn to_kilomoles(value: f64) -> f64 {
super::moles::to_kilomoles(to_moles(value))
}
}
pub mod micromoles {
pub fn to_moles(value: f64) -> f64 {
value / 1_000_000.0
}
pub fn to_millimoles(value: f64) -> f64 {
value / 1000.0
}
pub fn to_nanomoles(value: f64) -> f64 {
value * 1000.0
}
pub fn to_picomoles(value: f64) -> f64 {
value * 1_000_000.0
}
pub fn to_kilomoles(value: f64) -> f64 {
super::moles::to_kilomoles(to_moles(value))
}
}
pub mod nanomoles {
pub fn to_moles(value: f64) -> f64 {
value / 1_000_000_000.0
}
pub fn to_millimoles(value: f64) -> f64 {
value / 1_000_000.0
}
pub fn to_micromoles(value: f64) -> f64 {
value / 1000.0
}
pub fn to_picomoles(value: f64) -> f64 {
value * 1000.0
}
pub fn to_kilomoles(value: f64) -> f64 {
super::moles::to_kilomoles(to_moles(value))
}
}
pub mod picomoles {
pub fn to_moles(value: f64) -> f64 {
value / 1_000_000_000_000.0
}
pub fn to_millimoles(value: f64) -> f64 {
value / 1_000_000_000.0
}
pub fn to_micromoles(value: f64) -> f64 {
value / 1_000_000.0
}
pub fn to_nanomoles(value: f64) -> f64 {
value / 1000.0
}
pub fn to_kilomoles(value: f64) -> f64 {
super::moles::to_kilomoles(to_moles(value))
}
}
pub mod kilomoles {
pub fn to_moles(value: f64) -> f64 {
value * 1000.0
}
pub fn to_millimoles(value: f64) -> f64 {
super::moles::to_millimoles(to_moles(value))
}
pub fn to_micromoles(value: f64) -> f64 {
super::moles::to_micromoles(to_moles(value))
}
pub fn to_nanomoles(value: f64) -> f64 {
super::moles::to_nanomoles(to_moles(value))
}
pub fn to_picomoles(value: f64) -> f64 {
super::moles::to_picomoles(to_moles(value))
}
}
pub fn moles_to_millimoles(moles: f64) -> f64 {
moles::to_millimoles(moles)
}
pub fn millimoles_to_moles(millimoles: f64) -> f64 {
millimoles::to_moles(millimoles)
}
pub fn moles_to_micromoles(moles: f64) -> f64 {
moles::to_micromoles(moles)
}
pub fn micromoles_to_moles(micromoles: f64) -> f64 {
micromoles::to_moles(micromoles)
}
pub fn moles_to_nanomoles(moles: f64) -> f64 {
moles::to_nanomoles(moles)
}
pub fn nanomoles_to_moles(nanomoles: f64) -> f64 {
nanomoles::to_moles(nanomoles)
}
pub fn moles_to_kilomoles(moles: f64) -> f64 {
moles::to_kilomoles(moles)
}
pub fn kilomoles_to_moles(kilomoles: f64) -> f64 {
kilomoles::to_moles(kilomoles)
}
pub fn convert_amount(value: f64, from_unit: &str, to_unit: &str) -> Result<f64, String> {
let from_unit = from_unit.to_lowercase();
let to_unit = to_unit.to_lowercase();
let moles = match from_unit.as_str() {
"mol" | "mole" | "moles" => value,
"mmol" | "millimol" | "millimole" | "millimoles" => millimoles::to_moles(value),
"μmol" | "umol" | "micromol" | "micromole" | "micromoles" => micromoles::to_moles(value),
"nmol" | "nanomol" | "nanomole" | "nanomoles" => nanomoles::to_moles(value),
"pmol" | "picomol" | "picomole" | "picomoles" => picomoles::to_moles(value),
"kmol" | "kilomol" | "kilomole" | "kilomoles" => kilomoles::to_moles(value),
_ => return Err(format!("Unsupported amount unit: {}", from_unit)),
};
let result = match to_unit.as_str() {
"mol" | "mole" | "moles" => moles,
"mmol" | "millimol" | "millimole" | "millimoles" => moles::to_millimoles(moles),
"μmol" | "umol" | "micromol" | "micromole" | "micromoles" => moles::to_micromoles(moles),
"nmol" | "nanomol" | "nanomole" | "nanomoles" => moles::to_nanomoles(moles),
"pmol" | "picomol" | "picomole" | "picomoles" => moles::to_picomoles(moles),
"kmol" | "kilomol" | "kilomole" | "kilomoles" => moles::to_kilomoles(moles),
_ => return Err(format!("Unsupported amount unit: {}", to_unit)),
};
Ok(result)
}