Delete Decoder::read_map
This commit is contained in:
parent
42904b0219
commit
c6ad61a1bd
2 changed files with 26 additions and 37 deletions
|
@ -81,7 +81,7 @@ where
|
||||||
V: Decodable<D>,
|
V: Decodable<D>,
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> BTreeMap<K, V> {
|
fn decode(d: &mut D) -> BTreeMap<K, V> {
|
||||||
d.read_map(|d, len| {
|
let len = d.read_usize();
|
||||||
let mut map = BTreeMap::new();
|
let mut map = BTreeMap::new();
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
let key = Decodable::decode(d);
|
let key = Decodable::decode(d);
|
||||||
|
@ -89,7 +89,6 @@ where
|
||||||
map.insert(key, val);
|
map.insert(key, val);
|
||||||
}
|
}
|
||||||
map
|
map
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +144,7 @@ where
|
||||||
S: BuildHasher + Default,
|
S: BuildHasher + Default,
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> HashMap<K, V, S> {
|
fn decode(d: &mut D) -> HashMap<K, V, S> {
|
||||||
d.read_map(|d, len| {
|
let len = d.read_usize();
|
||||||
let state = Default::default();
|
let state = Default::default();
|
||||||
let mut map = HashMap::with_capacity_and_hasher(len, state);
|
let mut map = HashMap::with_capacity_and_hasher(len, state);
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
|
@ -154,7 +153,6 @@ where
|
||||||
map.insert(key, val);
|
map.insert(key, val);
|
||||||
}
|
}
|
||||||
map
|
map
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +221,7 @@ where
|
||||||
S: BuildHasher + Default,
|
S: BuildHasher + Default,
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> indexmap::IndexMap<K, V, S> {
|
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 state = Default::default();
|
||||||
let mut map = indexmap::IndexMap::with_capacity_and_hasher(len, state);
|
let mut map = indexmap::IndexMap::with_capacity_and_hasher(len, state);
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
|
@ -232,7 +230,6 @@ where
|
||||||
map.insert(key, val);
|
map.insert(key, val);
|
||||||
}
|
}
|
||||||
map
|
map
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,14 +200,6 @@ pub trait Decoder {
|
||||||
fn read_char(&mut self) -> char;
|
fn read_char(&mut self) -> char;
|
||||||
fn read_str(&mut self) -> Cow<'_, str>;
|
fn read_str(&mut self) -> Cow<'_, str>;
|
||||||
fn read_raw_bytes_into(&mut self, s: &mut [u8]);
|
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
|
/// Trait for types that can be serialized
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue