Skip to main content

a3s_runtime/contract/
artifact.rs

1use serde::{Deserialize, Serialize};
2
3/// Immutable artifact address understood by a Runtime provider.
4///
5/// `uri` tells the provider where to resolve the content while `digest` is the
6/// authoritative identity. Providers must never replace the digest with a
7/// mutable tag resolved at execution time.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(deny_unknown_fields)]
10pub struct ArtifactRef {
11    pub uri: String,
12    pub digest: String,
13    pub media_type: String,
14}
15
16impl ArtifactRef {
17    pub fn validate(&self) -> Result<(), String> {
18        super::validate_uri("artifact uri", &self.uri)?;
19        super::validate_digest(&self.digest)?;
20        super::validate_nonempty("artifact media_type", &self.media_type, 255)
21    }
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
25#[serde(deny_unknown_fields)]
26pub struct RuntimeOutputArtifact {
27    pub name: String,
28    pub artifact: ArtifactRef,
29    pub size_bytes: u64,
30}
31
32impl RuntimeOutputArtifact {
33    pub(crate) fn validate(&self) -> Result<(), String> {
34        super::validate_name("output artifact name", &self.name)?;
35        self.artifact.validate()
36    }
37}