Skip to content

Add Guard::into_inner_if_some#233

Open
asonix wants to merge 4 commits intofjall-rs:mainfrom
asonix:asonix/into-inner-if-some
Open

Add Guard::into_inner_if_some#233
asonix wants to merge 4 commits intofjall-rs:mainfrom
asonix:asonix/into-inner-if-some

Conversation

@asonix
Copy link
Copy Markdown

@asonix asonix commented Jan 10, 2026

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

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
Comment thread src/blob_tree/mod.rs
let kv = self.kv?;

if let Some(t) = pred(&kv.key.user_key) {
resolve_value_handle(
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve_value_handle needs access to the key slice, so the predicate can't take ownership of it.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@marvin-j97 marvin-j97 added enhancement New feature or request api labels Jan 12, 2026
@marvin-j97
Copy link
Copy Markdown
Contributor

    ) -> 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.

@asonix
Copy link
Copy Markdown
Author

asonix commented Jan 13, 2026

@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?

@marvin-j97
Copy link
Copy Markdown
Contributor

Right, no, I'm stupid - it would need a different signature.

@asonix
Copy link
Copy Markdown
Author

asonix commented Jan 13, 2026

We could return a Result<Result<(K, UserValue), UserKey)>> maybe, so if the K can't parse the unparsed key can still be accessed

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 guard.key() and then parse that key.

@asonix
Copy link
Copy Markdown
Author

asonix commented Jan 17, 2026

Changed to return Result<Result<(K, UserValue), UserKey>>, so the unparsed key can be made available for inspection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants