Something went wrong. Try again.
A git-based task manager
Something went wrong. Try again.
Rust
at feat/parser
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556use std::collections::btree_map::{IntoIter as BTreeIntoIter, Iter as BTreeMapIter};use std::collections::BTreeMap;use std::iter::Chain;
type Map = BTreeMap<String, String>;
#[allow(dead_code)]/// Holds xattributes in a way that allows for differentiating between attributes that have been/// added/modified or that were present when reading the file. This is an *optimization* over/// infrequently modified values.#[derive(Default, Clone, Debug)]pub(crate) struct Attrs { pub written: Map, pub updated: Map,}
impl IntoIterator for Attrs { type Item = (String, String);
type IntoIter = Chain<BTreeIntoIter<String, String>, BTreeIntoIter<String, String>>;
fn into_iter(self) -> Self::IntoIter { self.written.into_iter().chain(self.updated.into_iter()) }}
#[allow(dead_code)]impl Attrs { pub(crate) fn from_written(written: Map) -> Self { Self { written, ..Default::default() } }
pub(crate) fn get(&self, key: &str) -> Option<&String> { self.updated.get(key).or_else(|| self.written.get(key)) }
pub(crate) fn insert(&mut self, key: String, value: String) -> Option<String> { if self.updated.contains_key(&key) { self.updated.insert(key, value) } else { let maybe_old_value = self.written.get(&key); self.updated.insert(key, value); maybe_old_value.cloned() } }
pub(crate) fn iter( &self, ) -> Chain<BTreeMapIter<'_, String, String>, BTreeMapIter<'_, String, String>> { self.written.iter().chain(self.updated.iter()) }}