summaryrefslogtreecommitdiffstats
path: root/src/project.rs
blob: 26f0a8b40b64988e72aad1f7cda9cbf8b904b689 (plain)
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
use std::{path::PathBuf, time::Duration};

pub mod path;

#[cfg(feature = "git")]
pub mod git;

pub type ProjectParserGroup = Vec<Box<dyn ProjectParser>>;

pub trait ProjectParser {
    fn parse(&self, path_buf: PathBuf) -> Option<ProjectItem>;
}

impl ProjectParser for ProjectParserGroup {
    fn parse(&self, path_buf: std::path::PathBuf) -> Option<ProjectItem> {
        self.iter().find_map(|p| p.parse(path_buf.to_owned()))
    }
}

pub type ProjectItem = Box<dyn Project>;

pub trait Project: Timestamp {
    fn to_path_buf(&self) -> &PathBuf;
}

impl<T> Project for T
where
    T: Timestamp,
    T: AsRef<PathBuf>,
{
    fn to_path_buf(&self) -> &PathBuf {
        self.as_ref()
    }
}

pub trait Timestamp {
    fn timestamp(&self) -> &Duration;
}

impl<T> Timestamp for T
where
    T: AsRef<Duration>,
{
    fn timestamp(&self) -> &Duration {
        self.as_ref()
    }
}