Skip to content

Commit

Permalink
Use collect_map/seq to simplify serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Sep 18, 2020
1 parent 7704ad9 commit c39bb07
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::de::value::{MapDeserializer, SeqDeserializer};
use serde::de::{
Deserialize, Deserializer, Error, IntoDeserializer, MapAccess, SeqAccess, Visitor,
};
use serde::ser::{Serialize, SerializeMap, SerializeSeq, Serializer};
use serde::ser::{Serialize, Serializer};

use core::fmt::{self, Formatter};
use core::hash::{BuildHasher, Hash};
Expand All @@ -21,11 +21,7 @@ where
where
T: Serializer,
{
let mut map_serializer = serializer.serialize_map(Some(self.len()))?;
for (key, value) in self {
map_serializer.serialize_entry(key, value)?;
}
map_serializer.end()
serializer.collect_map(self)
}
}

Expand Down Expand Up @@ -99,11 +95,7 @@ where
where
Se: Serializer,
{
let mut set_serializer = serializer.serialize_seq(Some(self.len()))?;
for value in self {
set_serializer.serialize_element(value)?;
}
set_serializer.end()
serializer.collect_seq(self)
}
}

Expand Down

0 comments on commit c39bb07

Please sign in to comment.