summaryrefslogtreecommitdiffstats
path: root/src/path.rs
blob: 219e2748cc58c901e3098a90053b98d1458c6e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use std::{io::ErrorKind, path::PathBuf};

use crate::{parser::Parser, project::Project};

#[derive(Debug, Clone)]
pub struct PathMatcher(pub String);

impl Parser for PathMatcher {
    type Error = std::io::Error;

    #[tracing::instrument]
    fn parse(&self, path_buf: PathBuf) -> Result<Project, Self::Error> {
        if !path_buf.join(&self.0).exists() {
            return Err(std::io::Error::from(ErrorKind::NotFound));
        }

        path_buf.try_into()
    }
}