#[derive(Debug, Default)]
pub struct StaticRecord<T> {
inner: Vec<(&'static str, T)>,
}
impl<T> StaticRecord<T> {
#[inline]
pub fn new() -> Self {
Self { inner: Vec::new() }
}
#[inline]
pub fn add(&mut self, key: &'static str, value: T) {
self.inner.push((key, value));
}
#[inline]
pub fn find(&self, key: &str) -> Option<&T> {
self.inner
.iter()
.find_map(|(field, value)| (field == &key).then_some(value))
}
}
impl<T> IntoIterator for StaticRecord<T> {
type Item = (&'static str, T);
type IntoIter = std::vec::IntoIter<Self::Item>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.inner.into_iter()
}
}