Skip to main content

read_map

Function read_map 

Source
pub fn read_map<K, V, F, B>(
    len: usize,
    buf: &mut B,
    read_pair: F,
) -> Result<HashMap<K, V>, DecodeError>
where K: Hash + Eq, F: Fn(&mut B) -> Result<(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 a Result<(K, V), DecodeError>.

§Returns

  • Ok(HashMap<K, V>) - A HashMap containing 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_pair function returns an error while reading a key-value pair.

§Type Parameters

  • K - The type of the keys in the map. Must implement std::hash::Hash and Eq.
  • V - The type of the values in the map.
  • F - The type of the function used to read key-value pairs from the buffer.