Created
November 12, 2018 22:51
-
-
Save pschichtel/b76a3b46083f2ca80ae6f04f2cbe200a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate multimap; | |
use std::hash::Hash; | |
use multimap::MultiMap; | |
fn main() { | |
let mut mmap = MultiMap::new(); | |
mmap.insert(1, 'a'); | |
mmap.insert(1, 'a'); | |
mmap.insert(1, 'a'); | |
mmap.insert(1, 'a'); | |
let vec = vec!['a', 'b', 'c']; | |
let iter = vec.iter(); | |
mmap.insert_many(2, iter); | |
println!("{:?}", vec); | |
println!("{:?}", mmap) | |
} | |
trait InsertMany<K, V> { | |
fn insert_many<I: Iterator<Item=V>>(&mut self, k: K, i: I); | |
} | |
impl<K, V> InsertMany<K, V> for MultiMap<K, V> where K: Eq + Hash + Copy { | |
fn insert_many<I: Iterator<Item=V>>(&mut self, k: K, it: I) { | |
for value in it { | |
self.insert(k, value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.