You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to pass borrow checking, every key is cloned and pushed into a new vector, which is a little hacky and inefficient.
pubfnfor_each<F>(&mutself,f:F) -> Result<()>whereF:Fn(&[u8],&[u8]),{// too stupid, just in order to pass borrow checking. // FIXME: find a better way to implement this feature?letmut keys = vec![];for key inself.keys(){
keys.push(key.clone());}for key in keys {let r = self.get(&key)?;ifletSome(value) = r {f(&key,&value);}}Ok(())}
Just wonder is there a better way to implement the above feature? HOW?
Following implementation cannot be compiled, we will get error cannot borrow *self as mutable because it is also borrowed as immutable.
pubfnfor_each<F>(&mutself,f:F) -> Result<()>whereF:Fn(&[u8],&[u8]),{for key inself.keys(){let r = self.get(&key)?;ifletSome(value) = r {f(&key,&value);}}Ok(())}
The text was updated successfully, but these errors were encountered:
In order to pass borrow checking, every key is cloned and pushed into a new vector, which is a little hacky and inefficient.
Just wonder is there a better way to implement the above feature? HOW?
Following implementation cannot be compiled, we will get error
cannot borrow
*selfas mutable because it is also borrowed as immutable
.The text was updated successfully, but these errors were encountered: