Pass an owned value to log's methods? #701

Open
opened 2025-09-29 00:52:27 -05:00 by tisonkun · 0 comments
tisonkun commented 2025-09-29 00:52:27 -05:00 (Migrated from github.com)

Hi @KodrAus @Thomasdezeeuw,

According to the following code:

github.com/rust-lang/log@6e1735597b/src/__private_api.rs (L81)

github.com/rust-lang/log@6e1735597b/src/__private_api.rs (L103-L105)

Given that Record<'a> and Metadata<'a> already conatins all refs in their fields, and we have an owned value at the caller side, I'd like to know why we pass a ref &Record and &Metadata instead of Record<'a> and Metadata<'a>, to the log and enabled method.

I mean, is it possible to change (despite it's a breaking change, just think of it technically):

pub trait Log: Sync + Send {
    fn enabled(&self, metadata: &Metadata) -> bool;
    fn log(&self, record: &Record);
    fn flush(&self);
}

into

pub trait Log: Sync + Send {
    fn enabled(&self, metadata: Metadata<'_>) -> bool;
    fn log(&self, record: Record<'_>);
    fn flush(&self);
}

Any downside?

Hi @KodrAus @Thomasdezeeuw, According to the following code: https://github.com/rust-lang/log/blob/6e1735597bb21c5d979a077395df85e1d633e077/src/__private_api.rs#L81 https://github.com/rust-lang/log/blob/6e1735597bb21c5d979a077395df85e1d633e077/src/__private_api.rs#L103-L105 Given that `Record<'a>` and `Metadata<'a>` already conatins all refs in their fields, and we have an owned value at the caller side, I'd like to know why we pass a ref `&Record` and `&Metadata` instead of `Record<'a>` and `Metadata<'a>`, to the `log` and `enabled` method. I mean, is it possible to change (despite it's a breaking change, just think of it technically): ```rust pub trait Log: Sync + Send { fn enabled(&self, metadata: &Metadata) -> bool; fn log(&self, record: &Record); fn flush(&self); } ``` into ```rust pub trait Log: Sync + Send { fn enabled(&self, metadata: Metadata<'_>) -> bool; fn log(&self, record: Record<'_>); fn flush(&self); } ``` Any downside?
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-rust-lang/log#701
No description provided.