The issue with this is that you can make mistakes with the general-purposed functions.
a function `fn convertYardsToKm(value: i32): i32` doesn't fail when you give it a weight.
Whereas in Rust you'd write something like this:
#[derive(Copy, Clone)]
struct Yard(i32);
#[derive(Copy, Clone)]
struct Km(i32);
#[derive(Copy, Clone)]
struct Lbs(i32);
#[derive(Copy, Clone)]
struct Kg(i32);
and your functions becomes `fn convertYardsToKm(value: Yard): Km`You can group them in an enum
enum Measurement {
Yard(Yard(i32)),
Km(Km(i32)),
Lbs(Lbs(i32)),
Kg(Kg(i32)),
}
(Note that it would be nice if we could refer to `Measurement::Yard` as a type vs have to add a distinct `Yard` type).That way there is no confusion what you're putting in, and what type the output is, which has resulted in for example an emergency landing https://en.wikipedia.org/wiki/Gimli_Glider#Miscalculation_du... and loss of a Mars probe: https://en.wikipedia.org/wiki/Mars_Climate_Orbiter