use std::collections::HashMap;
use std::path::{Path, PathBuf};
#[derive(Debug, Default)]
pub struct DocumentStore {
versions: HashMap<PathBuf, i32>,
}
impl DocumentStore {
pub fn new() -> Self {
Self {
versions: HashMap::new(),
}
}
pub fn is_open(&self, path: &Path) -> bool {
self.versions.contains_key(path)
}
pub fn open(&mut self, path: PathBuf) -> i32 {
let version = 0;
self.versions.insert(path, version);
version
}
pub fn bump_version(&mut self, path: &Path) -> Option<i32> {
let version = self.versions.get_mut(path)?;
*version += 1;
Some(*version)
}
pub fn version(&self, path: &Path) -> Option<i32> {
self.versions.get(path).copied()
}
pub fn close(&mut self, path: &Path) -> Option<i32> {
self.versions.remove(path)
}
pub fn open_documents(&self) -> Vec<&PathBuf> {
self.versions.keys().collect()
}
}