use super::Descriptor;
use super::MediaTypes;
use super::Platform;
use crate::error::Error;
use crate::platform;
use crate::platform::ffi;
use std::collections::BTreeMap;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Index {
pub schema_version: isize,
pub media_type: String,
pub manifests: Vec<Descriptor>,
pub annotations: Option<BTreeMap<String, String>>,
pub subject: Option<Descriptor>,
pub artifact_type: Option<String>,
}
impl Index {
pub fn new(manifests: Vec<Descriptor>) -> Self {
Self {
schema_version: 2,
media_type: MediaTypes::INDEX.to_string(),
manifests,
annotations: None,
subject: None,
artifact_type: None,
}
}
pub fn runnable_platforms(&self) -> Result<Vec<Platform>, Error> {
platform::outcome(
ffi::cz_index_runnable_platforms(self.clone()),
"read an index's runnable platforms",
)
.map(|outcome| outcome.platforms())
}
}