aoc-core 0.1.2

Useful Advent of Code data structures, types and functions common to my Rust solutions.
Documentation
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};

/// Adds `with_capacity` function for [`rustc-hash`](https://docs.rs/rustc-hash) types.
pub trait FxHashWithCapacity {
    /// Creates an empty instance with the specified `capacity`.
    fn with_capacity(capacity: usize) -> Self;
}

#[allow(clippy::implicit_hasher)]
impl<K, V> FxHashWithCapacity for FxHashMap<K, V> {
    #[inline]
    fn with_capacity(capacity: usize) -> Self {
        Self::with_capacity_and_hasher(capacity, FxBuildHasher)
    }
}

#[allow(clippy::implicit_hasher)]
impl<V> FxHashWithCapacity for FxHashSet<V> {
    fn with_capacity(capacity: usize) -> Self {
        Self::with_capacity_and_hasher(capacity, FxBuildHasher)
    }
}

#[cfg(test)]
mod tests {
    use rustc_hash::{FxHashMap, FxHashSet};

    use super::FxHashWithCapacity;

    #[test]
    fn fxhashmap_fxhashwithcapacity() {
        let input = 8;
        let expected = 8;
        let output = FxHashMap::<u8, u8>::with_capacity(input).capacity();
        assert!(expected <= output, "\n input: {input:?}");
    }

    #[test]
    fn fxhashset_fxhashwithcapacity() {
        let input = 8;
        let expected = 8;
        let output = FxHashSet::<u8>::with_capacity(input).capacity();
        assert!(expected <= output, "\n input: {input:?}");
    }
}