Leverage static str key when possible #727
No reviewers
Labels
No labels
bug
duplicate
easy
enhancement
help wanted
invalid
question
rfc
structured-logging
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-rust-lang/log!727
Loading…
Reference in a new issue
No description provided.
Delete branch "leverage-static-str-key-when-possible"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Replace
&'k strinKey<'k>withMaybeStaticStr<'k>to leverage&'static strwhen in most cases it is.Open for review, especially on:
MaybeStaticStrcauses significant indirection.Otherwise, for downstream append, even if the key is a static str, one may have to
key.to_stringto resolve some lifetime issue. See:github.com/open-telemetry/opentelemetry-rust@f7b0dd999d/opentelemetry-appender-log/src/lib.rs (L216)(they haveKey::from_static_str)github.com/slog-rs/stdlog@252b6bb643/kv.rs (L46)(they haveslog::Key::from(static_str))This looks like a good change to me, thanks @tisonkun!
@ -35,15 +36,23 @@ impl ToKey for str {// If a new field (such as an optional index) is added to the key they must not affect comparisonMaybe
from_static. Not sure what a good name is, but both seem to be intuitive :PView changes since the review
@ -35,15 +36,23 @@ impl ToKey for str {// If a new field (such as an optional index) is added to the key they must not affect comparisonI think
from_static_stris a good name, because it adds to the existingfrom_strname 👍@ -35,15 +36,23 @@ impl ToKey for str {// If a new field (such as an optional index) is added to the key they must not affect comparisonActually, looking at our other methods that use this type, they all carry a
_staticsuffix, likemodule_path_static. So I think we should call thisfrom_str_static.As noted, we should call the method
from_str_static, to match the convention of other methods inlog@ -444,12 +444,16 @@ macro_rules! __log_logger {#[cfg(feature = "kv")]macro_rules! __log_key {Would it be possible to use the static version here as well? I think it would be confusing that
key = 42is static and"key" = 42is not.View changes since the review
@ -444,12 +444,16 @@ macro_rules! __log_logger {#[cfg(feature = "kv")]macro_rules! __log_key {:expris not necessary to be&'static. I'd like to know if we can distinguish the case here as well.I'll try to investigate it later.
@ -35,15 +36,23 @@ impl ToKey for str {// If a new field (such as an optional index) is added to the key they must not affect comparisonThis is updated.
@ -444,12 +444,16 @@ macro_rules! __log_logger {#[cfg(feature = "kv")]macro_rules! __log_key {756c279649supports this by determiningliteralas a special case. Also tests added.Thanks @tisonkun