// SPDX-License-Identifier: Apache-2.0 OR MIT
// This file is @generated by cargo-config2-internal-codegen
// (gen_de function at tools/codegen/src/main.rs).
// It is not intended for manual editing.

#![cfg_attr(rustfmt, rustfmt::skip)]
use std::path::Path;
use crate::{error::Result, merge::Merge, value::SetPath};
impl Merge for crate::de::Config {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.alias, low.alias, force)?;
        Merge::merge(&mut self.build, low.build, force)?;
        Merge::merge(&mut self.credential_alias, low.credential_alias, force)?;
        Merge::merge(&mut self.doc, low.doc, force)?;
        Merge::merge(&mut self.env, low.env, force)?;
        Merge::merge(
            &mut self.future_incompat_report,
            low.future_incompat_report,
            force,
        )?;
        Merge::merge(&mut self.cargo_new, low.cargo_new, force)?;
        Merge::merge(&mut self.http, low.http, force)?;
        Merge::merge(&mut self.net, low.net, force)?;
        Merge::merge(&mut self.registries, low.registries, force)?;
        Merge::merge(&mut self.registry, low.registry, force)?;
        Merge::merge(&mut self.source, low.source, force)?;
        Merge::merge(&mut self.target, low.target, force)?;
        Merge::merge(&mut self.term, low.term, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::Config {
    fn set_path(&mut self, path: &Path) {
        self.alias.set_path(path);
        self.build.set_path(path);
        self.credential_alias.set_path(path);
        self.doc.set_path(path);
        self.env.set_path(path);
        self.future_incompat_report.set_path(path);
        self.cargo_new.set_path(path);
        self.http.set_path(path);
        self.net.set_path(path);
        self.registries.set_path(path);
        self.registry.set_path(path);
        self.source.set_path(path);
        self.target.set_path(path);
        self.term.set_path(path);
    }
}
impl Merge for crate::de::BuildConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.jobs, low.jobs, force)?;
        Merge::merge(&mut self.rustc, low.rustc, force)?;
        Merge::merge(&mut self.rustc_wrapper, low.rustc_wrapper, force)?;
        Merge::merge(
            &mut self.rustc_workspace_wrapper,
            low.rustc_workspace_wrapper,
            force,
        )?;
        Merge::merge(&mut self.rustdoc, low.rustdoc, force)?;
        Merge::merge(&mut self.target, low.target, force)?;
        Merge::merge(&mut self.target_dir, low.target_dir, force)?;
        Merge::merge(&mut self.build_dir, low.build_dir, force)?;
        Merge::merge(&mut self.rustflags, low.rustflags, force)?;
        Merge::merge(&mut self.rustdocflags, low.rustdocflags, force)?;
        Merge::merge(&mut self.incremental, low.incremental, force)?;
        Merge::merge(&mut self.dep_info_basedir, low.dep_info_basedir, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::BuildConfig {
    fn set_path(&mut self, path: &Path) {
        self.jobs.set_path(path);
        self.rustc.set_path(path);
        self.rustc_wrapper.set_path(path);
        self.rustc_workspace_wrapper.set_path(path);
        self.rustdoc.set_path(path);
        self.target.set_path(path);
        self.target_dir.set_path(path);
        self.build_dir.set_path(path);
        self.rustflags.set_path(path);
        self.rustdocflags.set_path(path);
        self.incremental.set_path(path);
        self.dep_info_basedir.set_path(path);
    }
}
impl Merge for crate::de::TargetConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.linker, low.linker, force)?;
        Merge::merge(&mut self.runner, low.runner, force)?;
        Merge::merge(&mut self.rustflags, low.rustflags, force)?;
        Merge::merge(&mut self.rustdocflags, low.rustdocflags, force)?;
        Merge::merge(&mut self.rest, low.rest, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::TargetConfig {
    fn set_path(&mut self, path: &Path) {
        self.linker.set_path(path);
        self.runner.set_path(path);
        self.rustflags.set_path(path);
        self.rustdocflags.set_path(path);
        self.rest.set_path(path);
    }
}
impl Merge for crate::de::DocConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.browser, low.browser, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::DocConfig {
    fn set_path(&mut self, path: &Path) {
        self.browser.set_path(path);
    }
}
impl SetPath for crate::de::EnvConfigValue {
    fn set_path(&mut self, path: &Path) {
        match self {
            Self::Value(v) => {
                v.set_path(path);
            }
            Self::Table { value, force, relative } => {
                value.set_path(path);
                force.set_path(path);
                relative.set_path(path);
            }
        }
    }
}
impl Merge for crate::de::FutureIncompatReportConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.frequency, low.frequency, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::FutureIncompatReportConfig {
    fn set_path(&mut self, path: &Path) {
        self.frequency.set_path(path);
    }
}
impl Merge for crate::de::CargoNewConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.vcs, low.vcs, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::CargoNewConfig {
    fn set_path(&mut self, path: &Path) {
        self.vcs.set_path(path);
    }
}
impl Merge for crate::de::HttpConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.debug, low.debug, force)?;
        Merge::merge(&mut self.proxy, low.proxy, force)?;
        Merge::merge(&mut self.timeout, low.timeout, force)?;
        Merge::merge(&mut self.cainfo, low.cainfo, force)?;
        Merge::merge(&mut self.check_revoke, low.check_revoke, force)?;
        Merge::merge(&mut self.low_speed_limit, low.low_speed_limit, force)?;
        Merge::merge(&mut self.multiplexing, low.multiplexing, force)?;
        Merge::merge(&mut self.user_agent, low.user_agent, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::HttpConfig {
    fn set_path(&mut self, path: &Path) {
        self.debug.set_path(path);
        self.proxy.set_path(path);
        self.timeout.set_path(path);
        self.cainfo.set_path(path);
        self.check_revoke.set_path(path);
        self.low_speed_limit.set_path(path);
        self.multiplexing.set_path(path);
        self.user_agent.set_path(path);
    }
}
impl Merge for crate::de::NetConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.retry, low.retry, force)?;
        Merge::merge(&mut self.git_fetch_with_cli, low.git_fetch_with_cli, force)?;
        Merge::merge(&mut self.offline, low.offline, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::NetConfig {
    fn set_path(&mut self, path: &Path) {
        self.retry.set_path(path);
        self.git_fetch_with_cli.set_path(path);
        self.offline.set_path(path);
    }
}
impl Merge for crate::de::RegistriesConfigValue {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.index, low.index, force)?;
        Merge::merge(&mut self.token, low.token, force)?;
        Merge::merge(&mut self.credential_provider, low.credential_provider, force)?;
        Merge::merge(&mut self.protocol, low.protocol, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::RegistriesConfigValue {
    fn set_path(&mut self, path: &Path) {
        self.index.set_path(path);
        self.token.set_path(path);
        self.credential_provider.set_path(path);
        self.protocol.set_path(path);
    }
}
impl Merge for crate::de::RegistryConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.default, low.default, force)?;
        Merge::merge(&mut self.credential_provider, low.credential_provider, force)?;
        Merge::merge(&mut self.token, low.token, force)?;
        Merge::merge(
            &mut self.global_credential_providers,
            low.global_credential_providers,
            force,
        )?;
        Ok(())
    }
}
impl SetPath for crate::de::RegistryConfig {
    fn set_path(&mut self, path: &Path) {
        self.default.set_path(path);
        self.credential_provider.set_path(path);
        self.token.set_path(path);
        self.global_credential_providers.set_path(path);
    }
}
impl Merge for crate::de::SourceConfigValue {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.replace_with, low.replace_with, force)?;
        Merge::merge(&mut self.directory, low.directory, force)?;
        Merge::merge(&mut self.registry, low.registry, force)?;
        Merge::merge(&mut self.local_registry, low.local_registry, force)?;
        Merge::merge(&mut self.git, low.git, force)?;
        Merge::merge(&mut self.branch, low.branch, force)?;
        Merge::merge(&mut self.tag, low.tag, force)?;
        Merge::merge(&mut self.rev, low.rev, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::SourceConfigValue {
    fn set_path(&mut self, path: &Path) {
        self.replace_with.set_path(path);
        self.directory.set_path(path);
        self.registry.set_path(path);
        self.local_registry.set_path(path);
        self.git.set_path(path);
        self.branch.set_path(path);
        self.tag.set_path(path);
        self.rev.set_path(path);
    }
}
impl SetPath for crate::de::GlobalCredentialProviders {
    fn set_path(&mut self, path: &Path) {
        self.0.set_path(path);
    }
}
impl SetPath for crate::de::CredentialProvider {
    fn set_path(&mut self, path: &Path) {
        self.kind.set_path(path);
    }
}
impl Merge for crate::de::TermConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.quiet, low.quiet, force)?;
        Merge::merge(&mut self.verbose, low.verbose, force)?;
        Merge::merge(&mut self.color, low.color, force)?;
        Merge::merge(&mut self.progress, low.progress, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::TermConfig {
    fn set_path(&mut self, path: &Path) {
        self.quiet.set_path(path);
        self.verbose.set_path(path);
        self.color.set_path(path);
        self.progress.set_path(path);
    }
}
impl Merge for crate::de::TermProgress {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        Merge::merge(&mut self.when, low.when, force)?;
        Merge::merge(&mut self.width, low.width, force)?;
        Ok(())
    }
}
impl SetPath for crate::de::TermProgress {
    fn set_path(&mut self, path: &Path) {
        self.when.set_path(path);
        self.width.set_path(path);
    }
}
impl SetPath for crate::de::Flags {
    fn set_path(&mut self, path: &Path) {
        self.flags.set_path(path);
    }
}
impl SetPath for crate::de::ConfigRelativePath {
    fn set_path(&mut self, path: &Path) {
        self.0.set_path(path);
    }
}
impl SetPath for crate::de::PathAndArgs {
    fn set_path(&mut self, path: &Path) {
        self.path.set_path(path);
        self.args.set_path(path);
    }
}
impl SetPath for crate::de::StringList {
    fn set_path(&mut self, path: &Path) {
        self.list.set_path(path);
    }
}
impl SetPath for crate::de::StringOrArray {
    fn set_path(&mut self, path: &Path) {
        match self {
            Self::String(v) => {
                v.set_path(path);
            }
            Self::Array(v) => {
                v.set_path(path);
            }
        }
    }
}
