Bind lifetimes of &str returned from Key by the lifetime of 'k rather than the lifetime of the Key struct#648
Bind lifetimes of &str returned from Key by the lifetime of 'k rather than the lifetime of the Key struct#648Thomasdezeeuw merged 2 commits intorust-lang:masterfrom gbbosak:master
Conversation
… than the lifetime of the Key struct
src/kv/key.rs
Outdated
|
|
||
| impl<'k> AsRef<str> for Key<'k> { | ||
| fn as_ref(&self) -> &str { | ||
| fn as_ref(&self) -> &'k str { |
There was a problem hiding this comment.
This has no effect unless you add #[refine] (https://rust-lang.github.io/rfcs/3245-refined-impls.html).
There was a problem hiding this comment.
Hmm, it almost seems weird this compiles at all 👀 I hadn't seen #[refine] before. Thanks for pointing it out!
|
Thanks @gbbosak |
|
I should've left a comment on the type suggesting why it was that way, but we intentionally hadn't used |
|
@KodrAus do we want to revert the pr to keep that option open? |
|
@Thomasdezeeuw I think we should, and provide a way to get |
This allows things inside a Visitor to persist these strings for the lifetime of 'k without having to copy them.