From 4f024af7d6489bfc2af7dae05dbde182f4f2fb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 6 Jun 2019 09:25:19 +0300 Subject: [PATCH] gstreamer/serde: Fix compilation with serde feature enabled --- gstreamer/src/format_serde.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/gstreamer/src/format_serde.rs b/gstreamer/src/format_serde.rs index c5fdc266c..400a950be 100644 --- a/gstreamer/src/format_serde.rs +++ b/gstreamer/src/format_serde.rs @@ -9,7 +9,7 @@ use serde::de::{Deserialize, Deserializer}; 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: // "Default((Some(42)))" @@ -34,6 +34,30 @@ impl_ser_de!(Buffers); impl_ser_de!(Bytes); impl_ser_de!(Default); +impl Serialize for Undefined { + fn serialize(&self, serializer: S) -> Result { + self.0.serialize(serializer) + } +} + +impl<'de> Deserialize<'de> for Undefined { + fn deserialize>(deserializer: D) -> Result { + i64::deserialize(deserializer).map(Undefined) + } +} + +impl Serialize for Percent { + fn serialize(&self, serializer: S) -> Result { + self.0.serialize(serializer) + } +} + +impl<'de> Deserialize<'de> for Percent { + fn deserialize>(deserializer: D) -> Result { + Option::::deserialize(deserializer).map(Percent) + } +} + #[cfg(test)] mod tests { extern crate ron;