mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-23 08:36:31 +00:00
gstreamer/serde: Fix compilation with serde feature enabled
This commit is contained in:
parent
d1e562b9f6
commit
4f024af7d6
1 changed files with 25 additions and 1 deletions
|
@ -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<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)]
|
||||
mod tests {
|
||||
extern crate ron;
|
||||
|
|
Loading…
Reference in a new issue