mirror of
https://github.com/rm-dr/daisy
synced 2025-07-05 10:09:33 -07:00
Added unit fromstring
This commit is contained in:
@ -95,6 +95,22 @@ impl Unit {
|
||||
return u;
|
||||
}
|
||||
|
||||
pub fn from_string(s: &str) -> Option<Unit> {
|
||||
let b = match s {
|
||||
"m" => BaseUnit::Meter,
|
||||
"s" => BaseUnit::Second,
|
||||
"kg" => BaseUnit::Kilogram,
|
||||
"a" => BaseUnit::Ampere,
|
||||
"k" => BaseUnit::Kelvin,
|
||||
"mol" => BaseUnit::Mole,
|
||||
"c" => BaseUnit::Candela,
|
||||
_ => { return None; }
|
||||
};
|
||||
|
||||
let mut u = Unit::new();
|
||||
u.insert(b, 1f64);
|
||||
return Some(u);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user