Skip to main content

dict_depth

Function dict_depth 

Source
pub fn dict_depth<K, V>(d: &HashMap<K, V>) -> usize
where K: Hash + Eq,
Expand description

Get the nesting depth of a nested HashMap

ยงExample

use polyglot_sql::helper::dict_depth;
use std::collections::HashMap;

let empty: HashMap<String, ()> = HashMap::new();
assert_eq!(dict_depth(&empty), 1);

let mut nested: HashMap<String, HashMap<String, ()>> = HashMap::new();
nested.insert("a".into(), HashMap::new());
// Note: This returns 1 because we can't traverse into nested hashmaps generically