ruma_events/location/
zoomlevel_serde.rs

1//! `Serialize` and `Deserialize` implementations for extensible events (MSC1767).
2
3use js_int::UInt;
4use serde::{de, Deserialize};
5
6use super::{ZoomLevel, ZoomLevelError};
7
8impl<'de> Deserialize<'de> for ZoomLevel {
9    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
10    where
11        D: serde::Deserializer<'de>,
12    {
13        let uint = UInt::deserialize(deserializer)?;
14        if uint > Self::MAX.into() {
15            Err(de::Error::custom(ZoomLevelError::TooHigh))
16        } else {
17            Ok(Self(uint))
18        }
19    }
20}