1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::env;
use std::path::Path;

pub fn base_dir() -> String {
    env::var("CARGO_MANIFEST_DIR") // Set when started with `cargo run`
        .map(|p| {
            Path::new(&p)
                .parent()
                .expect("no parent dir")
                .to_string_lossy()
                .to_string()
        })
        .unwrap_or(
            env::current_dir()
                .map(|p| p.to_string_lossy().to_string())
                .expect("current working dir"),
        )
}

pub fn app_dir(subdir: &str) -> String {
    format!("{}/{subdir}", &base_dir())
}