79664105

Date: 2025-06-12 21:08:40
Score: 1
Natty:
Report link

As per @ChayimFriedman's comment, here is how to fix either attempt. Note that for attempt 1, in addition to removing the asterisk, it appears that you must add braces too.

    let mut map : BTreeMap<i32, HashSet<i32>> = BTreeMap::new();
    let mut value = HashSet::new();
    map.insert(1, value);

    // working attempt 1:
    map.entry(1).and_modify(|s| { s.insert(7);});

    // working attempt 2:
    let mut set = map.get_mut(&1);
    match set {
        Some(ref mut hashset) => {hashset.insert(77);},
        None => {},
    };
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @ChayimFriedman's
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Andrew Kelley