Updated everything and moved to hard tab indentation

This commit is contained in:
2025-01-08 19:20:34 +01:00
parent 7cdfe7e3c4
commit 52c8d1c95a
100 changed files with 5949 additions and 5998 deletions

View File

@@ -8,38 +8,38 @@ use never::Never;
/// Combine two hashmaps via an infallible value merger. See also
/// [try_join_maps]
pub fn join_maps<K: Eq + Hash, V>(
left: HashMap<K, V>,
right: HashMap<K, V>,
mut merge: impl FnMut(&K, V, V) -> V,
left: HashMap<K, V>,
right: HashMap<K, V>,
mut merge: impl FnMut(&K, V, V) -> V,
) -> HashMap<K, V> {
let (val, ev) = try_join_maps::<K, V, Never>(left, right, |k, l, r| Ok(merge(k, l, r)));
if let Some(e) = ev.first() {
match *e {}
}
val
let (val, ev) = try_join_maps::<K, V, Never>(left, right, |k, l, r| Ok(merge(k, l, r)));
if let Some(e) = ev.first() {
match *e {}
}
val
}
/// Combine two hashmaps via a fallible value merger. See also [join_maps]
pub fn try_join_maps<K: Eq + Hash, V, E>(
left: HashMap<K, V>,
mut right: HashMap<K, V>,
mut merge: impl FnMut(&K, V, V) -> Result<V, E>,
left: HashMap<K, V>,
mut right: HashMap<K, V>,
mut merge: impl FnMut(&K, V, V) -> Result<V, E>,
) -> (HashMap<K, V>, Vec<E>) {
let mut mixed = HashMap::with_capacity(left.len() + right.len());
let mut errors = Vec::new();
for (key, lval) in left {
let val = match right.remove(&key) {
None => lval,
Some(rval) => match merge(&key, lval, rval) {
Ok(v) => v,
Err(e) => {
errors.push(e);
continue;
},
},
};
mixed.insert(key, val);
}
mixed.extend(right);
(mixed, errors)
let mut mixed = HashMap::with_capacity(left.len() + right.len());
let mut errors = Vec::new();
for (key, lval) in left {
let val = match right.remove(&key) {
None => lval,
Some(rval) => match merge(&key, lval, rval) {
Ok(v) => v,
Err(e) => {
errors.push(e);
continue;
},
},
};
mixed.insert(key, val);
}
mixed.extend(right);
(mixed, errors)
}