use crate::error::InstallError;
pub trait ExtractContract {
type Manifest;
fn manifest_asset_name(&self) -> &'static str;
fn parse_manifest(
&self,
bytes: &[u8],
coords: &crate::RepoCoords,
) -> Result<Self::Manifest, InstallError>;
fn manifest_id(&self, manifest: &Self::Manifest) -> String;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct PluginExtractContract;
impl ExtractContract for PluginExtractContract {
type Manifest = nexo_plugin_manifest::PluginManifest;
fn manifest_asset_name(&self) -> &'static str {
"nexo-plugin.toml"
}
fn parse_manifest(
&self,
bytes: &[u8],
coords: &crate::RepoCoords,
) -> Result<Self::Manifest, InstallError> {
let text = std::str::from_utf8(bytes).map_err(|e| InstallError::ReleaseShape {
owner: coords.owner.clone(),
repo: coords.repo.clone(),
reason: format!("manifest is not valid UTF-8: {e}"),
})?;
toml::from_str::<nexo_plugin_manifest::PluginManifest>(text).map_err(|e| {
InstallError::ReleaseShape {
owner: coords.owner.clone(),
repo: coords.repo.clone(),
reason: format!("manifest parse failed: {e}"),
}
})
}
fn manifest_id(&self, manifest: &Self::Manifest) -> String {
manifest.plugin.id.clone()
}
}