nmd_core/artifact/
artifacts_collection.rs

1use std::path::PathBuf;
2
3use getset::{Getters, Setters};
4
5use super::{artifact_assets::ArtifactAssets, Artifact, ArtifactError};
6
7
8/// Final compilation result
9#[derive(Debug, Getters, Setters)]
10pub struct ArtifactsCollection {
11
12    #[getset(get = "pub", set = "pub")]
13    assets: Option<ArtifactAssets>,
14
15    #[getset(get = "pub", set = "pub")]
16    artifacts: Vec<Artifact>,
17
18    #[getset(get = "pub", set = "pub")]
19    output_path: PathBuf
20}
21
22
23#[allow(dead_code)]
24impl ArtifactsCollection {
25
26    pub fn new(output_path: PathBuf) -> Result<Self, ArtifactError> {
27
28        if !output_path.is_dir() {
29            return Err(ArtifactError::OutputPathNotDir)
30        }
31
32        Ok(Self {
33            assets: Option::None,
34            artifacts: Vec::new(),
35            output_path
36        })
37    }
38
39    // TODO
40    // pub fn add_artifact(&mut self, document_name: &String, document_content: &String) -> Result<(), ArtifactError> {
41
42    //     let final_location = self.output_path.join(document_name);
43
44    //     let mut document = CachedDiskResource::try_from(final_location)?;
45
46    //     document.set_cached_content(document_content);
47
48    //     self.artifacts.push(document);
49
50    //     Ok(())
51    // }
52}
53
54// impl Dumpable for ArtifactsCollection {
55//     fn dump(&mut self) -> Result<(), DumpError> {
56
57//         log::info!("dump artifacts collection...",);
58
59//         let error = self.artifacts.par_iter_mut().map(|artifact| {
60
61//             log::info!("dumping artifact in {:?}", artifact.output_path());
62
63//             artifact.dump()
64//         })
65//         .find_any(|result| result.is_err());
66
67//         if let Some(error) = error {
68//             return Err(error.err().unwrap());
69//         }
70
71//         Ok(())
72//     }
73// }