1pub mod artifact_assets;
2pub mod artifacts_collection;
3
4use std::fmt::Display;
5
6use getset::{CopyGetters, Getters, MutGetters, Setters};
7use thiserror::Error;
8
9
10use crate::resource::{disk_resource::DiskResource, Resource, ResourceError};
11
12use super::dumpable::{DumpConfiguration, DumpError, Dumpable};
13
14
15#[derive(Error, Debug)]
16pub enum ArtifactError {
17
18 #[error("the output path must be an existing directory because artifact can contain more than one file")]
19 OutputPathNotDir,
20
21 #[error(transparent)]
22 ResourceError(#[from] ResourceError)
23}
24
25pub type ArtifactContent = String;
26
27#[derive(Debug, Clone, Getters, MutGetters, CopyGetters, Setters)]
28pub struct Artifact {
29
30 #[getset(get = "pub", get_mut = "pub", set = "pub")]
31 content: ArtifactContent,
32}
33
34impl Artifact {
35 pub fn new(content: ArtifactContent) -> Self {
36
37 Self {
38 content
39 }
40 }
41}
42
43impl From<&str> for Artifact {
44 fn from(value: &str) -> Self {
45 Self::new(String::from(value))
46 }
47}
48
49impl From<&String> for Artifact {
50 fn from(value: &String) -> Self {
51 Self::new(value.clone())
52 }
53}
54
55impl From<String> for Artifact {
56 fn from(value: String) -> Self {
57 Self::new(value)
58 }
59}
60
61impl Display for Artifact {
62 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63 f.write_str(&self.content)
64 }
65}
66
67impl Dumpable for Artifact {
68 fn dump(&mut self, configuration: &DumpConfiguration) -> Result<(), DumpError> {
69
70 let path = configuration.output_path().clone();
71
72 log::info!("dump artifact in {:?}", path);
73
74 let mut disk_resource = DiskResource::try_from(path)?;
75
76 if configuration.force_dump() {
77 disk_resource.create_parents_dir()?;
78 }
79
80 disk_resource.write(&self.content)?;
81
82 Ok(())
83 }
84}
85
86impl Into<String> for Artifact {
87 fn into(self) -> String {
88 self.content
89 }
90}