ligen_core/generator/
file.rs1use std::path::PathBuf;
4use std::collections::HashMap;
5
6#[derive(Debug, Clone)]
8pub struct File {
9 pub path: PathBuf,
11 pub content: String
13}
14
15impl File {
16 pub fn new(path: PathBuf, content: String) -> Self {
18 Self { path, content }
19 }
20
21 pub fn write<S: AsRef<str>>(&mut self, content: S) {
23 self.content.push_str(content.as_ref());
24 }
25
26 pub fn writeln<S: AsRef<str>>(&mut self, content: S) {
28 self.content.push_str(content.as_ref());
29 self.content.push('\n');
30 }
31}
32
33#[derive(Debug, Default, Clone)]
35pub struct FileSet {
36 pub(crate) files: HashMap<PathBuf, File>
38}
39
40impl FileSet {
41 pub fn new() -> Self {
43 Self::default()
44 }
45
46 pub fn insert(&mut self, file: File) {
48 self.files.insert(file.path.clone(), file);
49 }
50
51 pub fn get_mut(&mut self, path: &PathBuf) -> Option<&mut File> {
53 self.files.get_mut(path)
54 }
55
56 pub fn entry(&mut self, path: &PathBuf) -> &mut File {
58 self.files.entry(path.to_path_buf()).or_insert(File::new(path.clone(), Default::default()))
59 }
60}