Skip to content

Unable to override bools in merge chain #2051

@thomas-zahner

Description

When merging configs there is no way to override bools in the merge chain with false. If one item in the merge chain is true it will always stay true. This is a known limitation that we should ideally work around in the long term. The workaround is to convert all bools of Config into Option<bool>. Then we can remove the bool case of the merge! macro and move the affected fields into the option case in the merge invocation.

Note that this is not a very pressing issue. It does not affect CLI options, as there is no way to set flags to false. (e.g. lychee --dump=false does not work)

Also see the relevant discussion.

macro_rules! merge {
(
option { $( $optional:ident ),* $(,)? },
chain { $( $chainable:ident ),* $(,)? },
bool { $( $bool:ident ),* $(,)? },
) => {
Config {
hosts,
// Merge chainable fields (e.g. `Vec` and `HashMap`)
$( $chainable: self.$chainable.into_iter().chain(other.$chainable).collect(), )*
// Use self if present, otherwise use other
$( $optional: self.$optional.or(other.$optional), )*
// Use `true` when self or other is `true`.
// Note that this has the drawback, that a value cannot be overwritten with
// `false` in the merge chain, as there is no way to distinguish
// between "default" `false` and user-provided `false`.
// We would have to use `Option<bool>` in order to do that.
// See: https://github.com/lycheeverse/lychee/issues/2051
$( $bool: self.$bool || other.$bool, )*
}
};
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions