// 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<()> {
        self.alias.merge(low.alias, force)?;
        self.build.merge(low.build, force)?;
        self.credential_alias.merge(low.credential_alias, force)?;
        self.doc.merge(low.doc, force)?;
        self.env.merge(low.env, force)?;
        self.future_incompat_report.merge(low.future_incompat_report, force)?;
        self.cargo_new.merge(low.cargo_new, force)?;
        self.http.merge(low.http, force)?;
        self.net.merge(low.net, force)?;
        self.registries.merge(low.registries, force)?;
        self.registry.merge(low.registry, force)?;
        self.target.merge(low.target, force)?;
        self.term.merge(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.target.set_path(path);
        self.term.set_path(path);
    }
}
impl Merge for crate::de::BuildConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        self.jobs.merge(low.jobs, force)?;
        self.rustc.merge(low.rustc, force)?;
        self.rustc_wrapper.merge(low.rustc_wrapper, force)?;
        self.rustc_workspace_wrapper.merge(low.rustc_workspace_wrapper, force)?;
        self.rustdoc.merge(low.rustdoc, force)?;
        self.target.merge(low.target, force)?;
        self.target_dir.merge(low.target_dir, force)?;
        self.rustflags.merge(low.rustflags, force)?;
        self.rustdocflags.merge(low.rustdocflags, force)?;
        self.incremental.merge(low.incremental, force)?;
        self.dep_info_basedir.merge(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.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<()> {
        self.linker.merge(low.linker, force)?;
        self.runner.merge(low.runner, force)?;
        self.rustflags.merge(low.rustflags, force)?;
        self.rustdocflags.merge(low.rustdocflags, 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);
    }
}
impl Merge for crate::de::DocConfig {
    fn merge(&mut self, low: Self, force: bool) -> Result<()> {
        self.browser.merge(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<()> {
        self.frequency.merge(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<()> {
        self.vcs.merge(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<()> {
        self.debug.merge(low.debug, force)?;
        self.proxy.merge(low.proxy, force)?;
        self.timeout.merge(low.timeout, force)?;
        self.cainfo.merge(low.cainfo, force)?;
        self.check_revoke.merge(low.check_revoke, force)?;
        self.low_speed_limit.merge(low.low_speed_limit, force)?;
        self.multiplexing.merge(low.multiplexing, force)?;
        self.user_agent.merge(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<()> {
        self.retry.merge(low.retry, force)?;
        self.git_fetch_with_cli.merge(low.git_fetch_with_cli, force)?;
        self.offline.merge(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<()> {
        self.index.merge(low.index, force)?;
        self.token.merge(low.token, force)?;
        self.credential_provider.merge(low.credential_provider, force)?;
        self.protocol.merge(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<()> {
        self.default.merge(low.default, force)?;
        self.credential_provider.merge(low.credential_provider, force)?;
        self.token.merge(low.token, force)?;
        self.global_credential_providers.merge(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 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<()> {
        self.quiet.merge(low.quiet, force)?;
        self.verbose.merge(low.verbose, force)?;
        self.color.merge(low.color, force)?;
        self.progress.merge(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<()> {
        self.when.merge(low.when, force)?;
        self.width.merge(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);
            }
        }
    }
}
