2
次のコードは機能しますが、is_empty
の定義が使用方法から離れすぎているため、表示されません。HashMapから空の値を削除する方法は何ですか?
fn remove(&mut self, index: I, primary_key: &Rc<K>) {
let is_empty;
{
let ks = self.data.get_mut(&index).unwrap();
ks.remove(primary_key);
is_empty = ks.is_empty();
}
// I have to wrap `ks` in an inner scope so that we can borrow `data` mutably.
if is_empty {
self.data.remove(&index);
}
}
ifブランチを入力する前に条件変数を削除する方法はありますか?
if {ks.is_empty()} {
self.data.remove(&index);
}