ruma_events/audio/amplitude_serde.rs
1//! `Serialize` and `Deserialize` implementations for extensible events (MSC1767).
2
3use js_int::UInt;
4use serde::Deserialize;
5
6use super::Amplitude;
7
8impl<'de> Deserialize<'de> for Amplitude {
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 Ok(Self(uint.min(Self::MAX.into())))
15 }
16}