1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
use std::cmp::Ordering; #[derive(Clone, Debug, Eq, Serialize, Deserialize)] pub struct Currency { pub name: String, pub rate: usize, pub alias: String, pub plural: Option<String>, pub optional: Option<bool>, } impl Currency { pub fn new( name: &str, rate: usize, alias: &str, plural: Option<String>, optional: Option<bool>, ) -> Currency { Currency { name: name.to_owned(), rate, alias: alias.to_owned(), plural, optional, } } pub fn is_optional(&self) -> bool { match self.optional { Some(optional) => optional, None => false, } } } impl Ord for Currency { fn cmp(&self, other: &Currency) -> Ordering { other.rate.cmp(&self.rate) } } impl PartialOrd for Currency { fn partial_cmp(&self, other: &Currency) -> Option<Ordering> { Some(self.cmp(other)) } } impl PartialEq for Currency { fn eq(&self, other: &Currency) -> bool { self.rate == other.rate } }