pub mod strategy;
use crate::libstd::{
num::{
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU16, NonZeroU32, NonZeroU64,
NonZeroU8, NonZeroUsize,
},
String,
};
#[cfg(feature = "macros")]
pub use azalia_config_macros::Merge;
pub trait Merge: Sized {
fn merge(&mut self, other: Self);
}
impl Merge for () {
fn merge(&mut self, _: Self) {}
}
impl<T> Merge for Option<T> {
fn merge(&mut self, mut other: Self) {
if !self.is_some() {
*self = other.take();
}
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(any(noeldoc, docsrs), doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<T> Merge for crate::libstd::Vec<T> {
fn merge(&mut self, other: Self) {
strategy::vec::extend(self, other);
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(any(noeldoc, docsrs), doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<K: Ord, V> Merge for crate::libstd::BTreeMap<K, V> {
fn merge(&mut self, other: Self) {
strategy::maps::btreemap::extend(self, other);
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(any(noeldoc, docsrs), doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<T: Ord> Merge for crate::libstd::BTreeSet<T> {
fn merge(&mut self, other: Self) {
strategy::sets::btreeset::extend(self, other);
}
}
#[cfg(feature = "std")]
#[cfg_attr(any(noeldoc, docsrs), doc(cfg(feature = "std")))]
impl<K: crate::libstd::Hash + Eq, V> Merge for crate::libstd::HashMap<K, V> {
fn merge(&mut self, other: Self) {
strategy::maps::hashmap::extend(self, other);
}
}
#[cfg(feature = "std")]
#[cfg_attr(any(noeldoc, docsrs), doc(cfg(feature = "std")))]
impl<T: crate::libstd::Hash + Eq> Merge for crate::libstd::HashSet<T> {
fn merge(&mut self, other: Self) {
strategy::sets::hashset::extend(self, other);
}
}
impl Merge for f32 {
fn merge(&mut self, other: Self) {
strategy::f32::without_negative(self, other);
}
}
impl Merge for f64 {
fn merge(&mut self, other: Self) {
strategy::f64::without_negative(self, other);
}
}
macro_rules! impl_unsigned_int {
($($Ty:ty)+) => {
$(impl Merge for $Ty {
fn merge(&mut self, other: Self) {
if *self == 0 && other == 0 {
return;
}
if *self != 0 && other == 0 {
return;
}
if *self == 0 && other > 0 {
*self = other;
}
if *self != other {
*self = other;
}
}
})*
};
}
impl_unsigned_int!(u8 u16 u32 u64 u128 usize);
macro_rules! impl_nonzero {
($($Ty:ty)+) => {
$(impl Merge for $Ty {
fn merge(&mut self, other: Self) {
if self.get() != other.get() {
*self = unsafe { <$Ty>::new_unchecked(other.get()) };
}
}
})*
};
}
impl_nonzero!(
NonZeroI8
NonZeroI16
NonZeroI32
NonZeroI64
NonZeroI128
NonZeroIsize
NonZeroU8
NonZeroU16
NonZeroU32
NonZeroU64
NonZeroUsize
);
macro_rules! impl_partialeq {
(
$(
$(#[$meta:meta])*
$Ty:ty
)*
) => {
$(
$(#[$meta])*
impl Merge for $Ty {
fn merge(&mut self, other: Self) {
if *self != other {
*self = other;
}
}
}
)*
};
}
impl_partialeq!(
i8
i16
i32
i64
i128
isize
bool
String
#[cfg(feature = "std")]
#[cfg_attr(any(noeldoc, docsrs), doc(cfg(feature = "std")))]
std::path::PathBuf
#[cfg(feature = "url")]
#[cfg_attr(any(noeldoc, docsrs), doc(cfg(feature = "url")))]
url::Url
#[cfg(feature = "tracing")]
#[cfg_attr(any(noeldoc, docsrs), doc(cfg(feature = "tracing")))]
tracing::Level
);