omen/
lib.rs

1use anyhow::Result;
2use askama::Template;
3use std::fs;
4use std::path::Path;
5
6#[derive(Template)]
7#[template(path = "main.rs.txt")]
8struct Maintemplate {
9    name: String,
10}
11
12#[derive(Template)]
13#[template(path = "lib.rs.txt")]
14struct LibTemplate {
15    name: String,
16}
17
18#[derive(Template)]
19#[template(path = "Cargo.toml.txt")]
20struct CargoTemplate {
21    name: String,
22}
23
24pub fn build_micro(name: &str) -> Result<()> {
25    let project_dir = Path::new(name);
26    fs::create_dir(project_dir)?;
27    fs::create_dir(project_dir.join("src"))?;
28
29    let main_template = Maintemplate {
30        name: name.to_string(),
31    };
32    fs::write(project_dir.join("src/main.rs"), main_template.render()?)?;
33    let lib_template = LibTemplate {
34        name: name.to_string(),
35    };
36    fs::write(project_dir.join("src/lib.rs"), lib_template.render()?)?;
37
38    let cargo_template = CargoTemplate {
39        name: name.to_string(),
40    };
41    fs::write(project_dir.join("Cargo.toml"), cargo_template.render()?)?;
42
43    Ok(())
44}
45
46mod templates {
47    use askama::Template;
48
49    #[derive(Template)]
50    #[template(path = "main.rs.txt")]
51    pub(crate) struct MainTemplate {
52        pub name: String,
53    }
54
55    #[derive(Template)]
56    #[template(path = "lib.rs.txt")]
57    pub(crate) struct LibTemplate {
58        pub name: String,
59    }
60
61    #[derive(Template)]
62    #[template(path = "Cargo.toml.txt")]
63    pub(crate) struct CargoTemplate {
64        pub name: String,
65    }
66}