1use std::collections::HashMap;
2use std::path::{Path, PathBuf};
3
4#[derive(Debug, Default)]
11pub struct DocumentStore {
12 versions: HashMap<PathBuf, i32>,
14}
15
16impl DocumentStore {
17 pub fn new() -> Self {
18 Self {
19 versions: HashMap::new(),
20 }
21 }
22
23 pub fn is_open(&self, path: &Path) -> bool {
25 self.versions.contains_key(path)
26 }
27
28 pub fn open(&mut self, path: PathBuf) -> i32 {
30 let version = 0;
31 self.versions.insert(path, version);
32 version
33 }
34
35 pub fn bump_version(&mut self, path: &Path) -> Option<i32> {
38 let version = self.versions.get_mut(path)?;
39 *version += 1;
40 Some(*version)
41 }
42
43 pub fn version(&self, path: &Path) -> Option<i32> {
45 self.versions.get(path).copied()
46 }
47
48 pub fn close(&mut self, path: &Path) -> Option<i32> {
50 self.versions.remove(path)
51 }
52
53 pub fn open_documents(&self) -> Vec<&PathBuf> {
55 self.versions.keys().collect()
56 }
57}