Fix various clippy warnings in the serde code

This commit is contained in:
Sebastian Dröge 2018-10-11 11:25:28 +03:00
parent 5d9a3b4272
commit fa29872863
6 changed files with 18 additions and 17 deletions

View file

@ -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> {
let structure = seq
.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 =
seq.next_element::<Option<CapsFeatures>>()?
.ok_or(de::Error::custom(
.ok_or_else(|| de::Error::custom(
"Expected an `Option<CapsFeature>` for `Caps` item",
))?;

View file

@ -35,7 +35,7 @@ impl<'de> Visitor<'de> for ClockTimeVisitor {
where
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> {

View file

@ -24,7 +24,7 @@ macro_rules! impl_ser_de(
impl<'de> Deserialize<'de> for $t {
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)
}
}
}

View file

@ -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> {
let name = seq
.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
.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)?
.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))
}
}
@ -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> {
let name = seq
.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);
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)
}

View file

@ -44,9 +44,11 @@ impl<'a> TagValuesSer<'a> {
impl<'a> Serialize for TagValuesSer<'a> {
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 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_() {
glib::Type::F64 => ser_tag!(value, seq, f64),
glib::Type::String => ser_tag!(value, seq, String),
@ -202,9 +204,9 @@ impl<'de, 'a> Visitor<'de> for TagValuesTupleVisitor<'a> {
let name = seq
.next_element::<String>()
.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))?
.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`"))
}
}

View file

@ -115,6 +115,7 @@ macro_rules! ser_value (
);
);
#[repr(C)]
pub(crate) struct SendValue(glib::SendValue);
impl SendValue {
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> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let send_value_vec = unsafe {
mem::transmute::<&[glib::SendValue], &[SendValue]>(
self.as_slice()
)
&*(self.as_slice() as *const [glib::SendValue] as *const [SendValue])
};
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> {
let type_name = seq
.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)?
.ok_or(de::Error::custom("Expected a value for `Value`"))?;
.ok_or_else(|| de::Error::custom("Expected a value for `Value`"))?;
Ok(send_value)
}
}