I'm quite new to rust, and have been messing around for about 4 days now. I have code which is pretty much identical, and I can't seem to figure out how to make them one impl block. Below the two impl blocks are listed.
impl<K: Display, V: Display> StringTable for HashMap<K, V> {
fn to_table(&self) -> Vec<String> {
let mut values = vec![[String::from("Keys:"), String::from("Values:")]];
for (key, value) in self {
values.push([format!("{}", key), format!("{}", value)]);
}
generate_string_grid(&values)
}
}
impl<K: Display, V: Display> StringTable for BTreeMap<K, V> {
fn to_table(&self) -> Vec<String> {
let mut values = vec![[String::from("Keys:"), String::from("Values:")]];
for (key, value) in self {
values.push([format!("{}", key), format!("{}", value)]);
}
generate_string_grid(&values)
}
}
Any help would be appreciated, thanks