rust-lang / rust-lang/log

Pass an owned value to log's methods?

Open
#701 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.5k
Forks
289
Avg merge
55m
Merged PRs (30d)
1

Description

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):

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/__private_api.rs at the linked lines and review the Log trait signatures for enabled and log. Trace how Record and Metadata are passed from the caller, then document the compatibility and ownership implications of changing those parameters; done means reaching a justified API decision.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design, observability
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.