Closed miguelff closed 1 year ago
Unfortunately, SharedString
does not work this way.
SharedString
represents a copy-on-write pointer that may be based on a &'static str
, but also may be based on a String
. It would be invalid to provide a static reference to String
if SharedString
itself was also not 'static
.
As the code currently exists, if you could construct KeyName
statically, then you could use the returned reference from SharedString
(i.e. KeyName::as_str
) statically as well.
Ohhhh! right, thanks for explaining. I completely misunderstood the code. Sorry for the noise.
No worries at all. 👍🏻
A
SharedString
is valid during the duration of the program, once built. This PR extends the lifetime of the string slice returned byas_str
to avoid needing to clone the key name.