如何从选项中提取值从 rustlings 中解决 hashmap2 问题

问题描述

我已经解决hashmap2 in the rustlings repository

fn fruit_basket(basket: &mut HashMap<Fruit,u32>) {
    for fruit in fruit_kinds {
        match fruit {
            Fruit::Apple => basket.entry(Fruit::Apple).or_insert(3),Fruit::Banana => basket.entry(Fruit::Banana).or_insert(3),Fruit::Mango => basket.entry(Fruit::Mango).or_insert(3),Fruit::Lichi => basket.entry(Fruit::Lichi).or_insert(3),Fruit::Pineapple => basket.entry(Fruit::Pineapple).or_insert(3),};
        // Todo: Put new fruits if not already present. Note that you
        // are not allowed to put any type of fruit that's already
        // present!
    }
}

现在我想用不同的方法解决它:

fn fruit_basket(basket: &mut HashMap<Fruit,Fruit::Banana => basket.insert(Fruit::Banana,3),};
    }
}

我收到此编译错误

enter image description here

通过阅读文档,我可以理解 insert 返回 Option 是导致问题的原因,但我不完全了解如何解决它。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)