use serde::Deserialize;
mod errors;
pub mod load;
mod parse;
mod tests;
use errors::ParseError;
#[derive(Debug, Deserialize, Clone)]
pub struct Plugin {
pub authors: Option<Vec<String>>,
pub name: String,
pub version: String,
pub description: Option<String>,
pub license: Option<String>,
pub path: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct Toml {
pub plugin: Plugin,
}
#[derive(Debug, Deserialize)]
pub struct Ron {
pub plugin: Plugin,
}
#[derive(Debug, Deserialize)]
pub struct Json {
pub plugin: Plugin,
}
pub trait PluginManager {
fn use_plugin(&self, f: impl Fn(Plugin));
}
impl PluginManager for Plugin {
fn use_plugin(&self, f: impl Fn(Plugin)) {
f(self.clone());
}
}
type PErr = ParseError;
impl_parse!(Toml, |file| toml::from_str(file)
.map_err(|err| PErr::Format(err.into())));
impl_parse!(Ron, |file| ron::from_str(file)
.map_err(|err| PErr::Format(err.into())));
impl_parse!(Json, |file| serde_json::from_str(file)
.map_err(|err| PErr::Format(err.into())));