use core::{ borrow::Borrow, fmt, hash::{BuildHasher, Hash}, }; use std::collections::{BTreeMap, HashMap}; use crate::{FormatKey, FormatKeyError}; impl FormatKey for HashMap where K: Borrow + Eq + Hash, V: fmt::Display, S: BuildHasher, { fn fmt(&self, key: &str, f: &mut fmt::Formatter<'_>) -> Result<(), FormatKeyError> { match self.get(key) { Some(v) => v.fmt(f).map_err(FormatKeyError::Fmt), None => Err(FormatKeyError::UnknownKey), } } } impl FormatKey for BTreeMap where K: Borrow + Ord, V: fmt::Display, { fn fmt(&self, key: &str, f: &mut fmt::Formatter<'_>) -> Result<(), FormatKeyError> { match self.get(key) { Some(v) => v.fmt(f).map_err(FormatKeyError::Fmt), None => Err(FormatKeyError::UnknownKey), } } }