use std::collections::BTreeMap;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::RuntimeKind;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RuntimeArtifacts {
pub runtime: RuntimeKind,
pub files: BTreeMap<String, PathBuf>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub buffers: BTreeMap<String, Vec<u8>>,
#[serde(default)]
pub options: BTreeMap<String, serde_json::Value>,
}
impl RuntimeArtifacts {
pub fn new(runtime: RuntimeKind) -> Self {
Self {
runtime,
files: BTreeMap::new(),
buffers: BTreeMap::new(),
options: BTreeMap::new(),
}
}
pub fn with_file(mut self, role: impl Into<String>, path: impl Into<PathBuf>) -> Self {
self.files.insert(role.into(), path.into());
self
}
pub fn primary_model(&self) -> Option<&PathBuf> {
self.files
.get("model")
.or_else(|| self.files.get("primary"))
}
pub fn with_buffer(mut self, role: impl Into<String>, bytes: Vec<u8>) -> Self {
self.buffers.insert(role.into(), bytes);
self
}
}