Skip to content

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

Description

@tisonkun

Hi @KodrAus @Thomasdezeeuw,

According to the following code:

logger.log(&builder.build());

log/src/__private_api.rs

Lines 103 to 105 in 6e17355

pub fn enabled<L: Log>(logger: L, level: Level, target: &str) -> bool {
logger.enabled(&Metadata::builder().level(level).target(target).build())
}

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions