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
#![feature(proc_macro_hygiene, decl_macro)]

// #[macro_use] extern crate rocket;

use std::path::{Path};
use std::fs::create_dir;

/// Give your API a mounting route and root dir.
///
/// # Examples
///
/// ```rust
/// ezrest::api("/api");
/// ```
pub fn api(base: &str) -> () {
    let root_dir = env!("CARGO_MANIFEST_DIR").to_string();
    let root = format!("{}{}{}", root_dir, "/src", base);
    // let root: PathBuf = PathBuf::from(root_dir);

    if !Path::exists(root.as_ref()) {
        create_dir(root_dir.to_owned() + "/src" + &base).map_err(|err| -> String {
            println!("Error creating root dir for api : {:?}", err);
            "Error creating root dir for api".into()
        });
    }
}