Skip to content

Leverage static str key when possible - #727

Merged
KodrAus merged 3 commits into
rust-lang:masterfrom
tisonkun:leverage-static-str-key-when-possible
Jun 1, 2026
Merged

Leverage static str key when possible#727
KodrAus merged 3 commits into
rust-lang:masterfrom
tisonkun:leverage-static-str-key-when-possible

Conversation

@tisonkun

Copy link
Copy Markdown
Contributor

Replace &'k str in Key<'k> with MaybeStaticStr<'k> to leverage &'static str when in most cases it is.

Open for review, especially on:

  1. Whether it is backward compatible.
  2. Whether MaybeStaticStr causes significant indirection.

Otherwise, for downstream append, even if the key is a static str, one may have to key.to_string to resolve some lifetime issue. See:

Signed-off-by: tison <wander4096@gmail.com>

@KodrAusKodrAus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like a good change to me, thanks @tisonkun!

Comment threadsrc/kv/key.rs Outdated

@KodrAusKodrAus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As noted, we should call the method from_str_static, to match the convention of other methods in log

Comment threadsrc/macros.rs Outdated
Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
tisonkun requested a review from KodrAusJune 1, 2026 17:11
Signed-off-by: tison <wander4096@gmail.com>

@KodrAusKodrAus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @tisonkun

@KodrAus
KodrAus merged commit c906cfb into rust-lang:masterJun 1, 2026
13 checks passed
@tisonkun
tisonkun deleted the leverage-static-str-key-when-possible branch June 3, 2026 01:34
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@tisonkun@Thomasdezeeuw@KodrAus