1
Fork 0

Delete Decoder::read_map

This commit is contained in:
Mark Rousskov 2022-02-09 18:19:18 -05:00
parent 42904b0219
commit c6ad61a1bd
2 changed files with 26 additions and 37 deletions

View file

@ -81,7 +81,7 @@ where
V: Decodable<D>,
{
fn decode(d: &mut D) -> BTreeMap<K, V> {
d.read_map(|d, len| {
let len = d.read_usize();
let mut map = BTreeMap::new();
for _ in 0..len {
let key = Decodable::decode(d);
@ -89,7 +89,6 @@ where
map.insert(key, val);
}
map
})
}
}
@ -145,7 +144,7 @@ where
S: BuildHasher + Default,
{
fn decode(d: &mut D) -> HashMap<K, V, S> {
d.read_map(|d, len| {
let len = d.read_usize();
let state = Default::default();
let mut map = HashMap::with_capacity_and_hasher(len, state);
for _ in 0..len {
@ -154,7 +153,6 @@ where
map.insert(key, val);
}
map
})
}
}
@ -223,7 +221,7 @@ where
S: BuildHasher + Default,
{
fn decode(d: &mut D) -> indexmap::IndexMap<K, V, S> {
d.read_map(|d, len| {
let len = d.read_usize();
let state = Default::default();
let mut map = indexmap::IndexMap::with_capacity_and_hasher(len, state);
for _ in 0..len {
@ -232,7 +230,6 @@ where
map.insert(key, val);
}
map
})
}
}

View file

@ -200,14 +200,6 @@ pub trait Decoder {
fn read_char(&mut self) -> char;
fn read_str(&mut self) -> Cow<'_, str>;
fn read_raw_bytes_into(&mut self, s: &mut [u8]);
fn read_map<T, F>(&mut self, f: F) -> T
where
F: FnOnce(&mut Self, usize) -> T,
{
let len = self.read_usize();
f(self, len)
}
}
/// Trait for types that can be serialized