Tahler / currency-rs

A library providing a way to represent currencies in Rust.
http://tahler.github.io/currency-rs/currency/index.html
MIT License
8 stars 4 forks source link

Hitchhikers Guide to the galaxy #2

Closed hoodie closed 8 years ago

hoodie commented 8 years ago

Hi there, I would very much like to use your crate. Unfortunately it currently panics a little bit too much. Though I have no idea on whether panicking when comparing € and $ isn't ok, I think at least it should not panic while parsing.

// I changed
Currency::from_string(&str) -> Currency
// to 
Currency::from_string(&str) -> Option<Currency>

What do you think?

Tahler commented 8 years ago

Wow thanks for the interest. I’ll go ahead and merge your request after updating some documentation.

Concerning the comparison, I think panicking should be done similar to the philosophy of exceptions. That is, panicking should only be done in exceptional cases. For this project I would consider a comparison between two different currencies to be a non-exceptional case, so I will make that change.

It would have been cool for the comparison to do some conversion based on current conversion rates, but the symbol is nothing but a character, so I figured it was out of scope.

Also, just out of curiosity, what are you using this library to make?

Tahler commented 8 years ago

I take that back about the comparison not panicking. The overridden comparing methods must return a bool, so there is no way of returning an Option<bool> or something to that effect.

hoodie commented 8 years ago

Hi, I am writing a little tool for managing invoices, so I need to calculate prices and taxes. I haven't gotten to that point yet though. I might be coming back to you. Thanks for the merge anyway.

Tahler commented 8 years ago

Please do, I'd love to get more input on how the currency library works out for you.