Closed BMorinDrifter closed 1 year ago
We return &str
because it's not actually a &'static str
under the hood, at least not always. We also don't return SharedString
because that would allocate a new String
if it wasn't created from &'static str
.
The correct thing to do is to clone the Key
. If it was created from &'static str
, then it'll be a cheap clone, otherwise it will allocate a new String
(or strings, depending on how the labels are configured). That is the optimal approach.
Because
Key::name()
returns a&str
instead of a&'static str
or SharedString, I either had to copy the string or retain the entire Key for internal book keeping in my collector (https://crates.io/crates/metrics_cloudwatch_embedded)Please advice on how to get a SharedString or add an accessor.