rust-lang / log

Logging implementation for Rust
https://docs.rs/log
Apache License 2.0
2.12k stars 248 forks source link

Fix incorrect lifetime in Value::to_str() #587

Closed peterjoel closed 9 months ago

peterjoel commented 10 months ago

Without this change, the following code will not compile:

let foo = record
    .key_values()
    .get(Key::from_str("foo"))
    .and_then(|val| val.to_str());

with the following error:

   |
32 |         .and_then(|val| val.to_str());
   |                         ^^^^^^^^^^^^ returns a reference to data owned by the current function
Thomasdezeeuw commented 10 months ago

Not really an incorrect lifetime though, the change introduces a broader/larger lifetime.

peterjoel commented 10 months ago

Thanks for the fast response!

And yes, incorrect was perhaps a little opinionated! What I meant was: shorter than necessary and likely unintentionally so.