pub fn read_map<K, V, F, B>(
len: usize,
buf: &mut B,
read_pair: F,
) -> Result<HashMap<K, V>, DecodeError>Expand description
Reads a map from the buffer and returns it as a HashMap.
This function is generic over the key and value types of the map, and it uses a provided function to read key-value pairs from the buffer.
§Arguments
len- The number of key-value pairs to read from the buffer.buf- A reference to the slice containing the encoded map data.read_pair- A function that reads a key-value pair from the buffer and returns it as aResult<(K, V), DecodeError>.
§Returns
Ok(HashMap<K, V>)- AHashMapcontaining the decoded key-value pairs if successful.Err(DecodeError)- An error if the decoding process fails.
§Errors
This function will return an error if:
- The
read_pairfunction returns an error while reading a key-value pair.
§Type Parameters
K- The type of the keys in the map. Must implementstd::hash::HashandEq.V- The type of the values in the map.F- The type of the function used to read key-value pairs from the buffer.