feat: Implement De/Serialize on schema

This commit is contained in:
Clément Renault 2019-09-16 14:22:59 +02:00
parent ba3ac5ea7b
commit ffc29a319f
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -190,6 +190,23 @@ impl Schema {
} }
} }
impl Serialize for Schema {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: serde::ser::Serializer,
{
self.to_builder().serialize(serializer)
}
}
impl<'de> Deserialize<'de> for Schema {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: serde::de::Deserializer<'de>,
{
let builder = SchemaBuilder::deserialize(deserializer)?;
Ok(builder.build())
}
}
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)] #[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct SchemaAttr(pub u16); pub struct SchemaAttr(pub u16);