(deserializer: D)
| 171 | |
| 172 | impl<'de> Deserialize<'de> for Duration { |
| 173 | fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 174 | where |
| 175 | D: serde::Deserializer<'de>, |
| 176 | { |
| 177 | struct DurationVisitor; |
| 178 | |
| 179 | impl de::Visitor<'_> for DurationVisitor { |
| 180 | type Value = Duration; |
| 181 | |
| 182 | fn expecting(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { |
| 183 | write!(f, "a byte array with size 12") |
| 184 | } |
| 185 | |
| 186 | fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E> |
| 187 | where |
| 188 | E: de::Error, |
| 189 | { |
| 190 | if v.len() != 12 { |
| 191 | Err(E::custom(format!( |
| 192 | "Expected byte array of length 12, but length is {}", |
| 193 | v.len() |
| 194 | ))) |
| 195 | } else { |
| 196 | let v_slice: [u8; 12] = v[..12].try_into().unwrap(); |
| 197 | Ok(Duration::from(v_slice)) |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | deserializer.deserialize_bytes(DurationVisitor) |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | #[cfg(test)] |
nothing calls this directly
no test coverage detected