Skip to content

Derive Default for Level and LevelFilter enums - #736

Open
ssrlive wants to merge 1 commit into
rust-lang:masterfrom
ssrlive:master
Open

Derive Default for Level and LevelFilter enums#736
ssrlive wants to merge 1 commit into
rust-lang:masterfrom
ssrlive:master

Conversation

@ssrlive

@ssrlive ssrlive commented Jul 29, 2026

Copy link
Copy Markdown

When using log crate, we might sometimes define a struct with the Default macro,
but if Level or LevelFilter doesn't implement the Default trait, this struct will fail to compile.

Therefore, I created this PR. I hope you will approve it and merge it.

#[derive(Debug, Clone, Default)]
pub struct Args {
    pub item1: Option<String>,

    /// Log level (off, error, warn, info, debug, trace)
    pub log: log::LevelFilter,
}

@Thomasdezeeuw

Copy link
Copy Markdown
Collaborator

I'm not sure about implementing default for the level, I imagine we might not be able to agree on what the default should be.

Btw you can also implement Default manually, this way you can continue with your project without having to wait on this.

@KodrAus

KodrAus commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR @ssrlive! I share the same reservations as @Thomasdezeeuw, and don’t believe we should implement Default for level. There are reasonable arguments for picking the lowest/highest/info and none is a universal default.

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

Successfully merging this pull request may close these issues.

3 participants