1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use std::{fs,io};
use std::ops::{Deref, DerefMut};
use std::path::{Path, PathBuf};
use std::collections::HashMap;
use chrono::{Date, Utc, Datelike};
use tempdir::TempDir;
use super::StorageResult;
use super::repo::GitStatus;
pub type FilePath = Path;
pub type FolderPath = Path;
pub type FilePathBuf = PathBuf;
pub type FolderPathBuf = PathBuf;
pub trait Storable: Send+Sync {
fn open_folder(&FolderPath) -> StorageResult<Self> where Self: Sized;
fn open_file(&FilePath) -> StorageResult<Self> where Self: Sized;
fn from_template(project_name: &str, template: &Path, data: &HashMap<&str, String>) -> StorageResult<StorableAndTempDir<Self>> where Self: Sized;
fn ident(&self) -> String{ self.dir().file_stem().and_then(|s|s.to_str()).unwrap().to_owned() }
fn short_desc(&self) -> String;
fn modified_date(&self) -> Option<Date<Utc>>;
fn year(&self) -> Option<i32>{ self.modified_date().map(|d|d.year()) }
fn delete_project_dir_if(&self, confirmed: impl Fn()->bool) -> io::Result<()> {
let folder = self.dir();
if confirmed(){
debug!("$ rm {}", folder.display());
fs::remove_dir_all(&folder)
} else {Ok(())}
}
fn index(&self) -> Option<String>;
fn prefix(&self) -> Option<String>;
fn set_file(&mut self, new_file:&Path);
fn set_git_status(&mut self, GitStatus){}
fn get_git_status(&self) -> GitStatus{GitStatus::Unknown}
fn file_extension() -> String {String::from("PROJECT")}
fn file(&self) -> FilePathBuf;
fn file_name(&self) -> String {
self.file().file_name().expect("filename ended in ..").to_string_lossy().into()
}
fn dir(&self) -> FolderPathBuf { self.file().parent().unwrap().to_owned() }
fn matches_filter(&self, key: &str, val: &str) -> bool;
fn matches_search(&self, term: &str) -> bool;
fn is_ready_for_archive(&self) -> bool;
}
pub struct StorableAndTempDir<S: Storable> {
pub storable: S,
pub temp_dir: TempDir,
}
impl<S: Storable> Deref for StorableAndTempDir<S> {
type Target = S;
fn deref(&self) -> &S {
&self.storable
}
}
impl<S: Storable> DerefMut for StorableAndTempDir<S> {
fn deref_mut(&mut self) -> &mut S {
&mut self.storable
}
}