Add Guard::into_inner_if_some#233
Conversation
Allows passing the Key slice to the predicate and receiving a parsed value, returning that parsed value as the first element of the returned tuple. This can avoid double-parsing of keys that might happen with just Guard::into_inner_if
| let kv = self.kv?; | ||
|
|
||
| if let Some(t) = pred(&kv.key.user_key) { | ||
| resolve_value_handle( |
There was a problem hiding this comment.
resolve_value_handle needs access to the key slice, so the predicate can't take ownership of it.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
) -> crate::Result<(K, Option<UserValue>)> {would probably be the more flexible API as it allows reusing the parsed key even if a value was chosen not to be loaded. |
|
@marvin-j97 could you explain how that would work? if the predicate returns None rather than Some(K), how could we then return a K from the function? |
|
Right, no, I'm stupid - it would need a different signature. |
|
We could return a I also think we don't care about this function returning a key without loading the value. If a user wants to do that they can simply call |
|
Changed to return |
Allows passing the Key slice to the predicate and receiving a parsed value, returning that parsed value as the first element of the returned tuple. This can avoid double-parsing of keys that might happen with just Guard::into_inner_if