Hacker News new | past | comments | ask | show | jobs | submit login

Thanks to generics you could theoretically work with whatever underlying type makes the most sense for your use-case.

    let v1 : Inches<Ratio> = Ratio::new(5, 8).into();
    let v2 : Inches<Ratio> = Ratio::new(3, 8).into();

    let v3 : Feet<_> = (v1 + v2).into();

    assert_equal!(v3, Ratio::new(1, 12));



no that's not the point. if you let rust automagically decide when and where to apply conversions you could easily wind up in a situation where you have more operations than you need, which increases numerical error, and also be a bitch to uncover or refactor to minimize conversions.


Rust doesn’t automatically apply conversions, full stop.

And with a thoughtful approach to the API, you could avoid numerical error entirely by using integral types.


That’s a good starting point. The temperature delta issue remains: adding and subtracting temperatures should create a different unit. Thankfully there aren’t a lot of non-linear units.


thats why i put the word "you" in there. rust will do whatever automagic conversions you specify in the impls. Perhaps i should have used the verb "make" instead of "let". if you make rust automagically convert.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: