gstreamer/serde: Fix compilation with serde feature enabled

This commit is contained in:
Sebastian Dröge 2019-06-06 09:25:19 +03:00
parent d1e562b9f6
commit 4f024af7d6

View file

@ -9,7 +9,7 @@
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use format::{Buffers, Bytes, Default}; use format::{Buffers, Bytes, Default, Percent, Undefined};
// Manual implementation for some types that would otherwise yield representations such as: // Manual implementation for some types that would otherwise yield representations such as:
// "Default((Some(42)))" // "Default((Some(42)))"
@ -34,6 +34,30 @@ impl_ser_de!(Buffers);
impl_ser_de!(Bytes); impl_ser_de!(Bytes);
impl_ser_de!(Default); impl_ser_de!(Default);
impl Serialize for Undefined {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.0.serialize(serializer)
}
}
impl<'de> Deserialize<'de> for Undefined {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
i64::deserialize(deserializer).map(Undefined)
}
}
impl Serialize for Percent {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.0.serialize(serializer)
}
}
impl<'de> Deserialize<'de> for Percent {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Option::<u32>::deserialize(deserializer).map(Percent)
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; extern crate ron;