use std::fmt;
use serde::{Deserialize, Serialize};
pub use crate::generated::{ModelId, NodeId, PlanHash, RequestId, RunId, Sha256Hash};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(from = "String", into = "String")]
pub struct ArtifactKey(String);
impl ArtifactKey {
pub const NODE_OUTPUT_V0: &'static str = "node_output.v0";
pub const RUN_OUTPUTS_V0: &'static str = "run_outputs.v0";
pub fn new(value: impl Into<String>) -> Self {
Self(value.into().trim().to_string())
}
pub fn node_output_v0() -> Self {
Self(Self::NODE_OUTPUT_V0.to_string())
}
pub fn run_outputs_v0() -> Self {
Self(Self::RUN_OUTPUTS_V0.to_string())
}
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl From<&str> for ArtifactKey {
fn from(value: &str) -> Self {
ArtifactKey::new(value)
}
}
impl From<String> for ArtifactKey {
fn from(value: String) -> Self {
ArtifactKey::new(value)
}
}
impl From<ArtifactKey> for String {
fn from(value: ArtifactKey) -> Self {
value.0
}
}
impl fmt::Display for ArtifactKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str())
}
}