We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
inf
NaN
1 parent 53f2877 commit 80ccf63Copy full SHA for 80ccf63
1 file changed
src/units.rs
@@ -53,7 +53,6 @@ macro_rules! base_unit_struct {
53
PartialOrd,
54
Default,
55
Serialize,
56
- Deserialize,
57
derive_more::Add,
58
derive_more::Sub,
59
)]
@@ -131,6 +130,19 @@ macro_rules! base_unit_struct {
131
130
self.0.total_cmp(&other.0)
132
}
133
+ impl<'de> Deserialize<'de> for $name {
134
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
135
+ where
136
+ D: serde::Deserializer<'de>,
137
+ {
138
+ let value = f64::deserialize(deserializer)?;
139
+ if !value.is_finite() {
140
+ Err(serde::de::Error::custom("Value cannot be NaN or infinite"))?;
141
+ }
142
+
143
+ Ok($name(value))
144
145
146
impl UnitType for $name {
147
/// Create from an f64 value
148
fn new(value: f64) -> Self {
0 commit comments