/** * This file was automatically generated by templates/versions.hbs. * DO NOT MODIFY IT BY HAND. Instead, modify templates/versions.hbs, * and run build script to regenerate this file. */ use serde_json::Value; use serde::{Serialize, Deserialize}; use polywrap_schemafy::schemafy; use crate::utils::sanitize_semver_version; use crate::error::Error; {{#each versions}} schemafy!( root: WrapManifest{{vsuffix version}} "schemas/{{version}}.json" ); {{/each}} #[derive(Clone)] pub enum AnyManifest { {{#each versions}} WrapManifest{{vsuffix version}}(WrapManifest{{vsuffix version}}), {{/each}} } impl AnyManifest { pub fn version(&self) -> String { match self { {{#each versions}} AnyManifest::WrapManifest{{vsuffix version}}(_) => sanitize_semver_version("{{version}}"), {{/each}} } } pub fn from_json_value(value: Value) -> Result { match value["version"].as_str().unwrap() { {{#each versions}} "{{version}}" => Ok(AnyManifest::WrapManifest{{vsuffix version}}(serde_json::from_value(value)?)), {{/each}} v => Err(Error::FromJSONError(format!("Invalid manifest version: {}", v))), } } pub fn to_json_value(&self) -> Result { match self { {{#each versions}} AnyManifest::WrapManifest{{vsuffix version}}(manifest) => Ok(serde_json::to_value(manifest)?), {{/each}} } } pub fn get_latest_version() -> String { sanitize_semver_version("{{latest_version}}") } } pub type WrapManifest = WrapManifest{{vsuffix latest_version}}; pub type WrapManifestAbi = WrapManifest01Abi;