forked from mirrors/gstreamer-rs
Fix various clippy warnings in the serde code
This commit is contained in:
parent
5d9a3b4272
commit
fa29872863
6 changed files with 18 additions and 17 deletions
|
@ -117,10 +117,10 @@ impl<'de> Visitor<'de> for CapsItemVisitor {
|
||||||
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
|
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
|
||||||
let structure = seq
|
let structure = seq
|
||||||
.next_element::<Structure>()?
|
.next_element::<Structure>()?
|
||||||
.ok_or(de::Error::custom("Expected a `Structure` for `Caps` item"))?;
|
.ok_or_else(|| de::Error::custom("Expected a `Structure` for `Caps` item"))?;
|
||||||
let features_option =
|
let features_option =
|
||||||
seq.next_element::<Option<CapsFeatures>>()?
|
seq.next_element::<Option<CapsFeatures>>()?
|
||||||
.ok_or(de::Error::custom(
|
.ok_or_else(|| de::Error::custom(
|
||||||
"Expected an `Option<CapsFeature>` for `Caps` item",
|
"Expected an `Option<CapsFeature>` for `Caps` item",
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl<'de> Visitor<'de> for ClockTimeVisitor {
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
u64::deserialize(deserializer).map(|value| ClockTime::from_nseconds(value))
|
u64::deserialize(deserializer).map(ClockTime::from_nseconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_none<E: de::Error>(self) -> Result<Self::Value, E> {
|
fn visit_none<E: de::Error>(self) -> Result<Self::Value, E> {
|
||||||
|
|
|
@ -24,7 +24,7 @@ macro_rules! impl_ser_de(
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for $t {
|
impl<'de> Deserialize<'de> for $t {
|
||||||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||||
Option::<u64>::deserialize(deserializer).map(|value| $t(value))
|
Option::<u64>::deserialize(deserializer).map($t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,12 +91,12 @@ impl<'de> Visitor<'de> for FieldVisitor {
|
||||||
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
|
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
|
||||||
let name = seq
|
let name = seq
|
||||||
.next_element::<String>()?
|
.next_element::<String>()?
|
||||||
.ok_or(de::Error::custom("Expected a value for `Value` name"))?;
|
.ok_or_else(|| de::Error::custom("Expected a value for `Value` name"))?;
|
||||||
let type_name = seq
|
let type_name = seq
|
||||||
.next_element::<String>()?
|
.next_element::<String>()?
|
||||||
.ok_or(de::Error::custom("Expected a value for `Value` type"))?;
|
.ok_or_else(|| de::Error::custom("Expected a value for `Value` type"))?;
|
||||||
let send_value = de_send_value!(type_name, seq)?
|
let send_value = de_send_value!(type_name, seq)?
|
||||||
.ok_or(de::Error::custom("Expected a value for `Value`"))?;
|
.ok_or_else(|| de::Error::custom("Expected a value for `Value`"))?;
|
||||||
Ok(FieldDe(name, send_value))
|
Ok(FieldDe(name, send_value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,10 +146,10 @@ impl<'de> Visitor<'de> for StructureVisitor {
|
||||||
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
|
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
|
||||||
let name = seq
|
let name = seq
|
||||||
.next_element::<String>()?
|
.next_element::<String>()?
|
||||||
.ok_or(de::Error::custom("Expected a name for the `Structure`"))?;
|
.ok_or_else(|| de::Error::custom("Expected a name for the `Structure`"))?;
|
||||||
let mut structure = Structure::new_empty(&name);
|
let mut structure = Structure::new_empty(&name);
|
||||||
seq.next_element_seed(FieldsDe(structure.as_mut()))?
|
seq.next_element_seed(FieldsDe(structure.as_mut()))?
|
||||||
.ok_or(de::Error::custom("Expected a sequence of `Field`s"))?;
|
.ok_or_else(|| de::Error::custom("Expected a sequence of `Field`s"))?;
|
||||||
|
|
||||||
Ok(structure)
|
Ok(structure)
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,11 @@ impl<'a> TagValuesSer<'a> {
|
||||||
|
|
||||||
impl<'a> Serialize for TagValuesSer<'a> {
|
impl<'a> Serialize for TagValuesSer<'a> {
|
||||||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
|
use std::ops::DerefMut;
|
||||||
|
|
||||||
let mut tag_iter = self.0.borrow_mut();
|
let mut tag_iter = self.0.borrow_mut();
|
||||||
let mut seq = serializer.serialize_seq(tag_iter.size_hint().1)?;
|
let mut seq = serializer.serialize_seq(tag_iter.size_hint().1)?;
|
||||||
while let Some(value) = tag_iter.next() {
|
for value in tag_iter.deref_mut() {
|
||||||
match value.type_() {
|
match value.type_() {
|
||||||
glib::Type::F64 => ser_tag!(value, seq, f64),
|
glib::Type::F64 => ser_tag!(value, seq, f64),
|
||||||
glib::Type::String => ser_tag!(value, seq, String),
|
glib::Type::String => ser_tag!(value, seq, String),
|
||||||
|
@ -202,9 +204,9 @@ impl<'de, 'a> Visitor<'de> for TagValuesTupleVisitor<'a> {
|
||||||
let name = seq
|
let name = seq
|
||||||
.next_element::<String>()
|
.next_element::<String>()
|
||||||
.map_err(|err| de::Error::custom(format!("Error reading Tag name. {:?}", err)))?
|
.map_err(|err| de::Error::custom(format!("Error reading Tag name. {:?}", err)))?
|
||||||
.ok_or(de::Error::custom("Expected a name for the `Tag` name"))?;
|
.ok_or_else(|| de::Error::custom("Expected a name for the `Tag` name"))?;
|
||||||
seq.next_element_seed(TagValues(name.as_str(), self.0))?
|
seq.next_element_seed(TagValues(name.as_str(), self.0))?
|
||||||
.ok_or(de::Error::custom("Expected a seq of values for the `Tag`"))
|
.ok_or_else(|| de::Error::custom("Expected a seq of values for the `Tag`"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,7 @@ macro_rules! ser_value (
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
pub(crate) struct SendValue(glib::SendValue);
|
pub(crate) struct SendValue(glib::SendValue);
|
||||||
impl SendValue {
|
impl SendValue {
|
||||||
pub(crate) fn from(send_value: glib::SendValue) -> Self {
|
pub(crate) fn from(send_value: glib::SendValue) -> Self {
|
||||||
|
@ -144,9 +145,7 @@ macro_rules! impl_ser_send_value_collection (
|
||||||
impl<'a> Serialize for $t<'a> {
|
impl<'a> Serialize for $t<'a> {
|
||||||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
let send_value_vec = unsafe {
|
let send_value_vec = unsafe {
|
||||||
mem::transmute::<&[glib::SendValue], &[SendValue]>(
|
&*(self.as_slice() as *const [glib::SendValue] as *const [SendValue])
|
||||||
self.as_slice()
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
send_value_vec.serialize(serializer)
|
send_value_vec.serialize(serializer)
|
||||||
}
|
}
|
||||||
|
@ -232,9 +231,9 @@ impl<'de> Visitor<'de> for SendValueVisitor {
|
||||||
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
|
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
|
||||||
let type_name = seq
|
let type_name = seq
|
||||||
.next_element::<String>()?
|
.next_element::<String>()?
|
||||||
.ok_or(de::Error::custom("Expected a value for `Value` type"))?;
|
.ok_or_else(|| de::Error::custom("Expected a value for `Value` type"))?;
|
||||||
let send_value = de_send_value!(type_name, seq)?
|
let send_value = de_send_value!(type_name, seq)?
|
||||||
.ok_or(de::Error::custom("Expected a value for `Value`"))?;
|
.ok_or_else(|| de::Error::custom("Expected a value for `Value`"))?;
|
||||||
Ok(send_value)
|
Ok(send_value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue