Commit ab9cd29b authored by François Laignel's avatar François Laignel Committed by Sebastian Dröge

serde: fmt pass

Note: clippy didn't raise any warning
parent d4fb10ef
......@@ -8,8 +8,8 @@
use serde::de::{Deserialize, Deserializer};
use serde::ser;
use serde::ser::{Serialize, Serializer, SerializeStruct};
use serde_bytes::{Bytes, ByteBuf};
use serde::ser::{Serialize, SerializeStruct, Serializer};
use serde_bytes::{ByteBuf, Bytes};
use Buffer;
use BufferFlags;
......@@ -70,8 +70,7 @@ impl From<BufferDe> for Buffer {
impl<'de> Deserialize<'de> for Buffer {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
BufferDe::deserialize(deserializer)
.map(|buffer_de| buffer_de.into())
BufferDe::deserialize(deserializer).map(|buffer_de| buffer_de.into())
}
}
......@@ -103,22 +102,19 @@ mod tests {
let res = ron::ser::to_string_pretty(&buffer, pretty_config);
assert_eq!(
Ok(
concat!(
"(",
" pts: Some(1),",
" dts: None,",
" duration: Some(5),",
" offset: 3,",
" offset_end: 4,",
" flags: (",
" bits: 1048592,",
" ),",
" buffer: \"AQIDBA==\",",
")"
)
.to_owned()
),
Ok(concat!(
"(",
" pts: Some(1),",
" dts: None,",
" duration: Some(5),",
" offset: 3,",
" offset_end: 4,",
" flags: (",
" bits: 1048592,",
" ),",
" buffer: \"AQIDBA==\",",
")"
).to_owned()),
res
);
......@@ -126,29 +122,27 @@ mod tests {
assert_eq!(
concat!(
"{",
"\"pts\":1,",
"\"dts\":null,",
"\"duration\":5,",
"\"offset\":3,",
"\"offset_end\":4,",
"\"flags\":{\"bits\":1048592},",
"\"buffer\":[1,2,3,4]",
"\"pts\":1,",
"\"dts\":null,",
"\"duration\":5,",
"\"offset\":3,",
"\"offset_end\":4,",
"\"flags\":{\"bits\":1048592},",
"\"buffer\":[1,2,3,4]",
"}"
)
.to_owned(),
).to_owned(),
res
);
let res = serde_pickle::to_vec(&buffer, true).unwrap();
assert_eq!(
vec![
128, 3, 125, 40, 88, 3, 0, 0, 0, 112, 116, 115, 74, 1, 0, 0, 0, 88, 3, 0, 0, 0, 100,
116, 115, 78, 88, 8, 0, 0, 0, 100, 117, 114, 97, 116, 105, 111, 110, 74, 5, 0, 0, 0,
88, 6, 0, 0, 0, 111, 102, 102, 115, 101, 116, 74, 3, 0, 0, 0, 88, 10, 0, 0, 0, 111,
102, 102, 115, 101, 116, 95, 101, 110, 100, 74, 4, 0, 0, 0, 88, 5, 0, 0, 0, 102, 108,
97, 103, 115, 125, 40, 88, 4, 0, 0, 0, 98, 105, 116, 115, 74, 16, 0, 16, 0, 117, 88,
6, 0, 0, 0, 98, 117, 102, 102, 101, 114, 67,
4, 1, 2, 3, 4, 117, 46
128, 3, 125, 40, 88, 3, 0, 0, 0, 112, 116, 115, 74, 1, 0, 0, 0, 88, 3, 0, 0, 0,
100, 116, 115, 78, 88, 8, 0, 0, 0, 100, 117, 114, 97, 116, 105, 111, 110, 74, 5, 0,
0, 0, 88, 6, 0, 0, 0, 111, 102, 102, 115, 101, 116, 74, 3, 0, 0, 0, 88, 10, 0, 0,
0, 111, 102, 102, 115, 101, 116, 95, 101, 110, 100, 74, 4, 0, 0, 0, 88, 5, 0, 0, 0,
102, 108, 97, 103, 115, 125, 40, 88, 4, 0, 0, 0, 98, 105, 116, 115, 74, 16, 0, 16,
0, 117, 88, 6, 0, 0, 0, 98, 117, 102, 102, 101, 114, 67, 4, 1, 2, 3, 4, 117, 46,
],
res
);
......@@ -211,9 +205,8 @@ mod tests {
116, 115, 78, 88, 8, 0, 0, 0, 100, 117, 114, 97, 116, 105, 111, 110, 74, 5, 0, 0, 0,
88, 6, 0, 0, 0, 111, 102, 102, 115, 101, 116, 74, 3, 0, 0, 0, 88, 10, 0, 0, 0, 111,
102, 102, 115, 101, 116, 95, 101, 110, 100, 74, 4, 0, 0, 0, 88, 5, 0, 0, 0, 102, 108,
97, 103, 115, 125, 40, 88, 4, 0, 0, 0, 98, 105, 116, 115, 74, 16, 0, 16, 0, 117, 88,
6, 0, 0, 0, 98, 117, 102, 102, 101, 114, 67,
4, 1, 2, 3, 4, 117, 46
97, 103, 115, 125, 40, 88, 4, 0, 0, 0, 98, 105, 116, 115, 74, 16, 0, 16, 0, 117, 88, 6,
0, 0, 0, 98, 117, 102, 102, 101, 114, 67, 4, 1, 2, 3, 4, 117, 46,
];
let buffer: Buffer = serde_pickle::from_slice(buffer_pickle).unwrap();
assert_eq!(buffer.get_pts(), 1.into());
......@@ -227,4 +220,4 @@ mod tests {
assert_eq!(data.as_slice(), vec![1, 2, 3, 4].as_slice());
}
}
}
\ No newline at end of file
}
......@@ -7,7 +7,7 @@
// except according to those terms.
use serde::de::{Deserialize, Deserializer, SeqAccess, Visitor};
use serde::ser::{Serialize, Serializer, SerializeSeq};
use serde::ser::{Serialize, SerializeSeq, Serializer};
use std::fmt;
......@@ -106,35 +106,32 @@ mod tests {
let res = ron::ser::to_string_pretty(&buffer_list, pretty_config);
assert_eq!(
Ok(
concat!(
"[",
" (",
" pts: Some(1),",
" dts: None,",
" duration: Some(4),",
" offset: 0,",
" offset_end: 4,",
" flags: (",
" bits: 0,",
" ),",
" buffer: \"AQIDBA==\",",
" ),",
" (",
" pts: Some(5),",
" dts: None,",
" duration: Some(2),",
" offset: 4,",
" offset_end: 6,",
" flags: (",
" bits: 0,",
" ),",
" buffer: \"BQY=\",",
" ),",
"]"
)
.to_owned()
),
Ok(concat!(
"[",
" (",
" pts: Some(1),",
" dts: None,",
" duration: Some(4),",
" offset: 0,",
" offset_end: 4,",
" flags: (",
" bits: 0,",
" ),",
" buffer: \"AQIDBA==\",",
" ),",
" (",
" pts: Some(5),",
" dts: None,",
" duration: Some(2),",
" offset: 4,",
" offset_end: 6,",
" flags: (",
" bits: 0,",
" ),",
" buffer: \"BQY=\",",
" ),",
"]"
).to_owned()),
res,
);
}
......
......@@ -8,7 +8,7 @@
use serde::de;
use serde::de::{Deserialize, Deserializer, SeqAccess, Visitor};
use serde::ser::{Serialize, Serializer, SerializeSeq, SerializeTuple};
use serde::ser::{Serialize, SerializeSeq, SerializeTuple, Serializer};
use std::fmt;
......@@ -70,15 +70,19 @@ impl<'de> Visitor<'de> for CapsItemVisitor {
}
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
let structure = seq.next_element::<Structure>()?
let structure = seq
.next_element::<Structure>()?
.ok_or(de::Error::custom("Expected a `Structure` for `Caps` item"))?;
// `CapsFeature` is not available in `gstreamer-rs` yet
// Fake the type for now and expect `None` as a value
let feature_option = seq.next_element::<Option<Structure>>()?
.ok_or(de::Error::custom("Expected an `Option<CapsFeature>` for `Caps` item"))?;
let feature_option = seq
.next_element::<Option<Structure>>()?
.ok_or(de::Error::custom(
"Expected an `Option<CapsFeature>` for `Caps` item",
))?;
if feature_option.is_some() {
Err(de::Error::custom(
"Found a value for `CapsFeature`, expected `None` (not implemented yet)"
"Found a value for `CapsFeature`, expected `None` (not implemented yet)",
))
} else {
Ok(CapsItemDe(structure))
......@@ -143,23 +147,20 @@ mod tests {
let res = ron::ser::to_string_pretty(&caps, pretty_config);
assert_eq!(
Ok(
concat!(
"[",
" ((\"foo/bar\", [",
" (\"int\", \"i32\", 12),",
" (\"bool\", \"bool\", true),",
" (\"string\", \"String\", \"bla\"),",
" (\"fraction\", \"Fraction\", (1, 2)),",
" (\"array\", \"Array\", [",
" (\"i32\", 1),",
" (\"i32\", 2),",
" ]),",
" ]), None),",
"]"
)
.to_owned()
),
Ok(concat!(
"[",
" ((\"foo/bar\", [",
" (\"int\", \"i32\", 12),",
" (\"bool\", \"bool\", true),",
" (\"string\", \"String\", \"bla\"),",
" (\"fraction\", \"Fraction\", (1, 2)),",
" (\"array\", \"Array\", [",
" (\"i32\", 1),",
" (\"i32\", 2),",
" ]),",
" ]), None),",
"]"
).to_owned()),
res,
);
}
......
......@@ -35,8 +35,7 @@ impl<'de> Visitor<'de> for ClockTimeVisitor {
where
D: Deserializer<'de>,
{
u64::deserialize(deserializer)
.and_then(|value| Ok(ClockTime::from_nseconds(value)))
u64::deserialize(deserializer).and_then(|value| Ok(ClockTime::from_nseconds(value)))
}
fn visit_none<E: de::Error>(self) -> Result<Self::Value, E> {
......
......@@ -7,7 +7,7 @@
// except according to those terms.
use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer, SerializeStruct};
use serde::ser::{Serialize, SerializeStruct, Serializer};
use DateTime;
impl<'a> Serialize for DateTime {
......@@ -53,8 +53,7 @@ impl From<DateTimeDe> for DateTime {
impl<'de> Deserialize<'de> for DateTime {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
DateTimeDe::deserialize(deserializer)
.and_then(|datetime_de| Ok(datetime_de.into()))
DateTimeDe::deserialize(deserializer).and_then(|datetime_de| Ok(datetime_de.into()))
}
}
......@@ -76,21 +75,18 @@ mod tests {
let res = ron::ser::to_string_pretty(&datetime, pretty_config);
assert_eq!(
Ok(
concat!(
"(",
" tz_offset: 2,",
" y: 2018,",
" m: 5,",
" d: 28,",
" h: 16,",
" mn: 6,",
" s: 42,",
" us: 841000,",
")"
)
.to_owned()
),
Ok(concat!(
"(",
" tz_offset: 2,",
" y: 2018,",
" m: 5,",
" d: 28,",
" h: 16,",
" mn: 6,",
" s: 42,",
" us: 841000,",
")"
).to_owned()),
res,
);
......
......@@ -497,8 +497,8 @@ mod tests {
use super::Buffers;
use super::Bytes;
use ClockTime;
use super::Default;
use ClockTime;
use Format;
use GenericFormattedValue;
......@@ -568,8 +568,8 @@ mod tests {
extern crate ron;
extern crate serde_json;
use GenericFormattedValue;
use Format;
use GenericFormattedValue;
::init().unwrap();
......
......@@ -7,7 +7,7 @@
// except according to those terms.
use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer, SerializeStruct};
use serde::ser::{Serialize, SerializeStruct, Serializer};
use Buffer;
use BufferList;
......@@ -67,8 +67,7 @@ impl From<SampleDe> for Sample {
impl<'de> Deserialize<'de> for Sample {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
SampleDe::deserialize(deserializer)
.and_then(|sample_de| Ok(sample_de.into()))
SampleDe::deserialize(deserializer).and_then(|sample_de| Ok(sample_de.into()))
}
}
......@@ -136,49 +135,46 @@ mod tests {
let res = ron::ser::to_string_pretty(&sample, pretty_config.clone());
assert_eq!(
Ok(
concat!(
"(",
" buffer: Some((",
" pts: Some(1),",
" dts: None,",
" duration: Some(4),",
" offset: 0,",
" offset_end: 4,",
" flags: (",
" bits: 0,",
" ),",
" buffer: \"AQIDBA==\",",
" )),",
" buffer_list: None,",
" caps: Some([",
" ((\"sample/caps\", [",
" (\"int\", \"i32\", 12),",
" (\"bool\", \"bool\", true),",
" ]), None),",
" ]),",
" segment: Some((",
" flags: (",
" bits: 9,",
" ),",
" rate: 1,",
" applied_rate: 0.9,",
" format: Time,",
" base: 123,",
" offset: 42,",
" start: 1024,",
" stop: 2048,",
" time: 1042,",
" position: 256,",
" duration: -1,",
" )),",
" info: Some((\"sample.info\", [",
" (\"f3\", \"i32\", 123),",
" ])),",
")"
)
.to_owned()
),
Ok(concat!(
"(",
" buffer: Some((",
" pts: Some(1),",
" dts: None,",
" duration: Some(4),",
" offset: 0,",
" offset_end: 4,",
" flags: (",
" bits: 0,",
" ),",
" buffer: \"AQIDBA==\",",
" )),",
" buffer_list: None,",
" caps: Some([",
" ((\"sample/caps\", [",
" (\"int\", \"i32\", 12),",
" (\"bool\", \"bool\", true),",
" ]), None),",
" ]),",
" segment: Some((",
" flags: (",
" bits: 9,",
" ),",
" rate: 1,",
" applied_rate: 0.9,",
" format: Time,",
" base: 123,",
" offset: 42,",
" start: 1024,",
" stop: 2048,",
" time: 1042,",
" position: 256,",
" duration: -1,",
" )),",
" info: Some((\"sample.info\", [",
" (\"f3\", \"i32\", 123),",
" ])),",
")"
).to_owned()),
res
);
......@@ -198,42 +194,39 @@ mod tests {
let res = ron::ser::to_string_pretty(&sample, pretty_config);
assert_eq!(
Ok(
concat!(
"(",
" buffer: Some((",
" pts: Some(1),",
" dts: None,",
" duration: Some(4),",
" offset: 0,",
" offset_end: 4,",
" flags: (",
" bits: 0,",
" ),",
" buffer: \"AQIDBA==\",",
" )),",
" buffer_list: None,",
" caps: None,",
" segment: Some((",
" flags: (",
" bits: 0,",
" ),",
" rate: 1,",
" applied_rate: 1,",
" format: Time,",
" base: 0,",
" offset: 0,",
" start: 0,",
" stop: -1,",
" time: 0,",
" position: 0,",
" duration: -1,",
" )),",
" info: None,",
")"
)
.to_owned()
),
Ok(concat!(
"(",
" buffer: Some((",
" pts: Some(1),",
" dts: None,",
" duration: Some(4),",
" offset: 0,",
" offset_end: 4,",
" flags: (",
" bits: 0,",
" ),",
" buffer: \"AQIDBA==\",",
" )),",
" buffer_list: None,",
" caps: None,",
" segment: Some((",
" flags: (",
" bits: 0,",
" ),",
" rate: 1,",
" applied_rate: 1,",
" format: Time,",
" base: 0,",
" offset: 0,",
" start: 0,",
" stop: -1,",
" time: 0,",
" position: 0,",
" duration: -1,",
" )),",
" info: None,",
")"
).to_owned()),
res
);
}
......
......@@ -7,7 +7,7 @@
// except according to those terms.
use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer, SerializeStruct};
use serde::ser::{Serialize, SerializeStruct, Serializer};
use Format;
use GenericFormattedValue;
......@@ -54,13 +54,34 @@ impl From<SegmentDe> for Segment {
segment.set_rate(segment_de.rate);
segment.set_applied_rate(segment_de.applied_rate);
segment.set_format(segment_de.format);
segment.set_base(GenericFormattedValue::new(segment_de.format, segment_de.base));
segment.set_offset(GenericFormattedValue::new(segment_de.format, segment_de.offset));
segment.set_start(GenericFormattedValue::new(segment_de.format, segment_de.start));
segment.set_stop(GenericFormattedValue::new(segment_de.format, segment_de.stop));
segment.set_time(GenericFormattedValue::new(segment_de.format, segment_de.time));
segment.set_position(GenericFormattedValue::new(segment_de.format, segment_de.position));
segment.set_duration(GenericFormattedValue::new(segment_de.format, segment_de.duration));
segment.set_base(GenericFormattedValue::new(
segment_de.format,
segment_de.base,
));
segment.set_offset(GenericFormattedValue::new(
segment_de.format,
segment_de.offset,
));
segment.set_start(GenericFormattedValue::new(
segment_de.format,
segment_de.start,
));
segment.set_stop(GenericFormattedValue::new(
segment_de.format,
segment_de.stop,
));
segment.set_time(GenericFormattedValue::new(
segment_de.format,
segment_de.time,
));
segment.set_position(GenericFormattedValue::new(
segment_de.format,
segment_de.position,
));
segment.set_duration(GenericFormattedValue::new(
segment_de.format,
segment_de.duration,
));
segment
}
......@@ -68,8 +89,7 @@ impl From<SegmentDe> for Segment {
impl<'de> Deserialize<'de> for Segment {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
SegmentDe::deserialize(deserializer)
.and_then(|segment_de| Ok(segment_de.into()))
SegmentDe::deserialize(deserializer).and_then(|segment_de| Ok(segment_de.into()))
}
}
......@@ -105,26 +125,23 @@ mod tests {
let res = ron::ser::to_string_pretty(&segment, pretty_config);
assert_eq!(
Ok(
concat!(
"(",
" flags: (",
" bits: 9,",
" ),",
" rate: 1,",
" applied_rate: 0.9,",
" format: Time,",
" base: 123,",
" offset: 42,",
" start: 1024,",
" stop: 2048,",
" time: 1042,",
" position: 256,",
" duration: -1,",
")"