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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use ordered_float::OrderedFloat;
#[cfg(feature="serialization")]
use serde::ser::{Serialize, Serializer};
use std::fmt;
use std::cmp::{PartialOrd, Ord, PartialEq, Eq, Ordering};
use std::ops::Deref;
use std::convert;
#[derive(Copy, Clone, Debug)]
pub struct Tax(OrderedFloat<f64>);
impl Tax {
pub fn new(value: f64) -> Self {
Tax(OrderedFloat(value))
}
pub fn value(&self) -> f64 {
*self.0.as_ref()
}
}
#[cfg(feature="serialization")]
impl Serialize for Tax{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
self.0.as_ref().to_string().serialize(serializer)
}
}
impl Ord for Tax {
fn cmp(&self, other: &Self) -> Ordering {
self.0.cmp(&other.0)
}
}
impl Eq for Tax {}
impl PartialEq for Tax {
fn eq(&self, other: &Self) -> bool {
self.0.eq(&other.0)
}
}
impl PartialOrd for Tax {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.partial_cmp(&other.0)
}
}
impl Deref for Tax {
type Target = OrderedFloat<f64>;
fn deref(&self) -> &OrderedFloat<f64> {
&self.0
}
}
impl fmt::Display for Tax {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl convert::Into<f64> for Tax {
fn into(self) -> f64 {
self.0.into_inner()
}
}
impl convert::From<f64> for Tax {
fn from(value:f64) -> Tax {
Tax::new(value)
}
}