use std::{
collections::{hash_map::Iter, HashMap},
hash::Hash,
iter::IntoIterator,
};
use serde::Deserialize;
#[derive(Clone, Deserialize, Debug)]
pub struct Pipeline<K: Hash + Eq, V> {
pipeline: HashMap<K, V>,
}
impl<K: Hash + Eq, V> Pipeline<K, V> {
#[inline]
#[must_use]
pub fn new(pipeline: HashMap<K, V>) -> Self {
Self { pipeline }
}
#[inline]
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)> {
self.into_iter()
}
#[inline]
#[must_use]
pub fn get(&self, id: &K) -> Option<&V> {
self.pipeline.get(id)
}
#[inline]
#[must_use]
pub fn contains_key(&self, id: &K) -> bool {
self.pipeline.contains_key(id)
}
}
impl<'a, K: Eq + Hash, V> IntoIterator for &'a Pipeline<K, V> {
type IntoIter = Iter<'a, K, V>;
type Item = (&'a K, &'a V);
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.pipeline.iter()
}
}