flex_version/
serde.rs

1use std::borrow::Cow;
2
3use serde::de::Error;
4
5use super::Version;
6
7impl<'de> serde::Deserialize<'de> for Version {
8    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
9    where
10        D: serde::Deserializer<'de>,
11    {
12        let version_str = <Cow<str>>::deserialize(deserializer)?;
13        version_str.parse().map_err(Error::custom)
14    }
15}
16
17impl serde::Serialize for Version {
18    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
19    where
20        S: serde::Serializer,
21    {
22        serializer.collect_str(self)
23    }
24}