#[deprecated(
since = "0.1.0",
note = "used in old versions of azalia before crates.io release. scheduled for removal in v0.2"
)]
pub use string as strings;
pub mod string {
use crate::libstd::String;
pub fn append(left: &mut String, right: String) {
left.push_str(&right);
}
pub fn overwrite(left: &mut String, right: String) {
*left = right;
}
pub fn overwrite_empty(left: &mut String, right: String) {
if left.is_empty() {
*left = right;
}
}
}
pub mod bool {
pub fn only_if_falsy(lhs: &mut bool, rhs: bool) {
if !*lhs {
*lhs = rhs;
}
}
}
macro_rules! mk_floating_strategies {
($Ty:ty) => {
#[doc = concat!("Merges any [`", stringify!($Ty), "`][prim@", stringify!($Ty), "] without allowing negatives")]
#[doc = concat!("use azalia_config::merge::strategy::", stringify!($Ty), "::without_negative;")]
#[doc = concat!("let mut x: ", stringify!($Ty), " = 32.0;")]
pub fn without_negative(lhs: &mut $Ty, rhs: $Ty) {
if *lhs < 0.0 || rhs < 0.0 {
return;
}
with_negatives(lhs, rhs);
}
#[doc = concat!("Merges any [`", stringify!($Ty), "`][prim@", stringify!($Ty), "] with allowing negatives")]
#[doc = concat!("use azalia_config::merge::strategy::", stringify!($Ty), "::with_negatives;")]
#[doc = concat!("let mut x: ", stringify!($Ty), " = 32.0;")]
pub fn with_negatives(lhs: &mut $Ty, rhs: $Ty) {
if *lhs == 0.0 && rhs == 0.0 {
return;
}
if *lhs != 0.0 && rhs == 0.0 {
return;
}
if *lhs != rhs {
*lhs = rhs;
}
}
};
}
pub mod f32 {
mk_floating_strategies!(f32);
}
pub mod f64 {
mk_floating_strategies!(f64);
}
macro_rules! mk_collection_strategies {
(
$Ty:ty => ($($f:tt)*)
) => {
pub fn extend<$($f)*>(lhs: &mut $Ty, rhs: $Ty) {
lhs.extend(rhs);
}
pub fn overwrite<$($f)*>(lhs: &mut $Ty, rhs: $Ty) {
*lhs = rhs;
}
};
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(any(noeldoc, docsrs), cfg(any(feature = "std", feature = "alloc")))]
pub mod maps {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(any(noeldoc, docsrs), cfg(any(feature = "std", feature = "alloc")))]
pub mod btreemap {
use crate::libstd::BTreeMap;
mk_collection_strategies!(BTreeMap<K, V> => (K: Ord, V));
}
#[cfg(feature = "std")]
#[cfg_attr(any(noeldoc, docsrs), cfg(feature = "std"))]
pub mod hashmap {
use crate::libstd::{Hash, HashMap};
mk_collection_strategies!(HashMap<K, V> => (K: Hash + Eq, V));
}
}
pub mod sets {
pub mod btreeset {
use crate::libstd::BTreeSet;
mk_collection_strategies!(BTreeSet<T> => (T: Ord));
pub fn append<T: Ord>(left: &mut BTreeSet<T>, mut right: BTreeSet<T>) {
left.append(&mut right);
}
pub fn overwrite_empty<T: Ord>(lhs: &mut BTreeSet<T>, mut right: BTreeSet<T>) {
if lhs.is_empty() {
lhs.append(&mut right);
}
}
}
pub mod hashset {
use crate::libstd::{Hash, HashSet};
mk_collection_strategies!(HashSet<T> => (T: Hash + Eq));
}
}
pub mod vec {
use crate::libstd::Vec;
mk_collection_strategies!(Vec<T> => (T));
pub fn append<T>(left: &mut Vec<T>, mut right: Vec<T>) {
left.append(&mut right);
}
pub fn overwrite_empty<T>(lhs: &mut Vec<T>, mut right: Vec<T>) {
if lhs.is_empty() {
lhs.append(&mut right);
}
}
}