1use std::{fs, path::Path};
2
3pub struct Exists<'p> {
4 path: &'p str,
5}
6
7impl<'p> Exists<'p> {
8 pub fn check(path: &'p str) -> Self { Self { path } }
9 pub fn folder(&self) -> bool { Path::new(self.path).is_dir() }
10 pub fn file(&self) -> bool { Path::new(self.path).exists() }
11 pub fn empty(&self) -> bool { fs::metadata(Path::new(self.path)).map(|m| m.len() == 0).unwrap_or(true) }
12}
13
14#[doc(hidden)]
15#[macro_export]
16macro_rules! _lib_file_exists {
17 ($path: expr) => {
18 $crate::fs::Exists::check($path).file()
19 };
20}
21
22#[doc(hidden)]
23#[macro_export]
24macro_rules! _lib_folder_exists {
25 ($path: expr) => {
26 $crate::fs::Exists::check($path).folder()
27 };
28}
29
30#[doc(hidden)]
31#[macro_export]
32macro_rules! _lib_path_empty {
33 ($path: expr) => {
34 $crate::fs::Exists::check($path).empty()
35 };
36}
37
38#[doc(hidden)]
39#[macro_export]
40macro_rules! _lib_exists {
41 ($path: expr) => {
42 $crate::fs::Exists::check($path)
43 };
44}
45
46#[doc(inline)]
47pub use _lib_file_exists as file_exists;
48
49#[doc(inline)]
50pub use _lib_folder_exists as folder_exists;
51
52#[doc(inline)]
53pub use _lib_path_empty as path_empty;
54
55#[doc(inline)]
56pub use _lib_exists as exists;