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
use std::{fs, path::Path};

pub struct Exists<'p> {
    path: &'p str,
}

impl<'p> Exists<'p> {
    pub fn check(path: &'p str) -> Self { Self { path } }
    pub fn folder(&self) -> bool { Path::new(self.path).is_dir() }
    pub fn file(&self) -> bool { Path::new(self.path).exists() }
    pub fn empty(&self) -> bool { fs::metadata(Path::new(self.path)).map(|m| m.len() == 0).unwrap_or(true) }
}

#[macro_export]
macro_rules! file_exists {
    ($path: expr) => {
        Exists::check($path).file()
    };
}

#[macro_export]
macro_rules! folder_exists {
    ($path: expr) => {
        Exists::check($path).folder()
    };
}

#[macro_export]
macro_rules! path_empty {
    ($path: expr) => {
        Exists::check($path).empty()
    };
}

#[macro_export]
macro_rules! exists {
    ($path: expr) => {
        Exists::check($path)
    };
}