ref-fvm
ref-fvm copied to clipboard
Refactor AMT to use iter_mut Instead of for_each_mut
This PR refactors the AMT mplementation by replacing internal iteration via for_each_mut with external iteration using iter_mut and adds a test case showing the use case of the iter_mut function .
Motivation:
Solves #1996
Progress:
- [x] The iter_mut function yields a Smart pointer
Amtptr. - [x]
Amtptrcan be dereferenced immutably. - [x] Can be dereferenced mutably.
- [ ] Can be deleted to yield the inner value.
[!NOTE] Instead of using the
deref_mut, theget_mutfunction can be used instead as written in the test case and as shown below
for ptr in new_amt.iter_mut() {
let current_idx = ptr.0;
let mut val = ptr.1;
let mut val_ref = val.get_mut();
f(current_idx, &mut ValueMut::new(&mut *val_ref)).unwrap();
}