Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate the lifetime of Visit trait explicitly #3177

Open
thynson opened this issue Dec 20, 2024 · 0 comments
Open

Annotate the lifetime of Visit trait explicitly #3177

thynson opened this issue Dec 20, 2024 · 0 comments

Comments

@thynson
Copy link

thynson commented Dec 20, 2024

Feature Request

Motivation

The current trait definition of Visit, is blocking visitors from being implemented without copying string in safe Rust, the tracing-log contains an example for it, see https://github.com/tokio-rs/tracing/blob/master/tracing-log/src/lib.rs#L525C1-L540C6

Proposal

Fixing this issue, unfortunately, requires breaking change.

To make it possible to achieve the goal, the definition of the trait must ensure the visitor itself cannot outlives fields.

As the result, the lifetime of functions in Visit from tracing-core should be explicit annotated, taking record_str as example,

pub trait Visit {
    //...
    fn record_str(&mut self, field: &Field, value: &str);
}

should be modified to

pub trait Visit<'a> {
    //...
    fn record_str<'f>(&mut self, field: &'f Field, value: &'f str) where 'f: 'a;
}

Here is a snippets to prove that it should work.

https://godbolt.org/z/6s8P6Tv14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant