Skip to content

Remove FnOnce requirement#2

Merged
piccoloser merged 1 commit intomainfrom
load_or_default
Mar 14, 2025
Merged

Remove FnOnce requirement#2
piccoloser merged 1 commit intomainfrom
load_or_default

Conversation

@piccoloser
Copy link
Owner

Changes in This PR

Changes to Config::load_or_default()

  • No longer requires a FnOnce() -> Config as its second argument
  • Now accepts a Config instead, without a closure
// Before (Disliked by Clippy)
Config::load_or_default(CONFIG_INI, || {
    return sectioned_defaults! {
    // ...
    };
})

The issue with the original implementation was that clippy would recommend removing the unneeded return statement. Doing so, however, would lead to errors because sectioned_defaults! and general_defaults! create configurations by running Config::builder().set("...", "...").build(); without returning anything. The only other option that wouldn't be flagged by Clippy was to format your closure this way:

// Before (Accepted by Clippy, disliked by cargo fmt)
Config::load_or_default(CONFIG_INI, || sectioned_defaults! {
    // ...
})

... And then running cargo fmt would change it to this:

// Before (Broken after cargo fmt)
Config::load_or_default(CONFIG_INI, || {
    sectioned_defaults! {
        // ...
    }
})

This adds curly braces around the macro and breaks the function execution immediately.

With the new implementation, you can simply do this:

// New implementation
Config::load_or_default(CONFIG_INI, sectioned_defaults! {
        // ...
})

@piccoloser
Copy link
Owner Author

This PR resolves #3

@piccoloser piccoloser linked an issue Mar 14, 2025 that may be closed by this pull request
@piccoloser piccoloser merged commit 8ee88ee into main Mar 14, 2025
1 check passed
@piccoloser piccoloser deleted the load_or_default branch March 14, 2025 15:40
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.

Config::load_or_default() is disliked by Clippy

1 participant