Post AcdUwMg2NOkaoTsMNs by wtfrank@mastodon.social
(DIR) More posts by wtfrank@mastodon.social
(DIR) Post #AcdUwMg2NOkaoTsMNs by wtfrank@mastodon.social
2023-12-09T12:47:25Z
0 likes, 1 repeats
In #rust when you have a hashmap and want to insert or modify an entry, there's a pattern where you chain .and_modify().or_insert().If you are inserting a complicated new entry, you might want to define the new entry first in one place, and then insert it, but closure move rules interfere.Any way to define (a,b,c) once?let hashmap = HashMap::<Vec<(A, B,C)>>::default();let new_entry = (a, b, c);hashmap.entry(z).and_modify(|e| { e.push( new_entry ) }).or_insert(vec![new_entry]);