1use serde::Deserialize;
2
3mod errors;
4pub mod load;
5mod parse;
6mod tests;
7use errors::ParseError;
8
9#[derive(Debug, Deserialize, Clone)]
10pub struct Plugin {
11 pub authors: Option<Vec<String>>,
12 pub name: String,
13 pub version: String,
14 pub description: Option<String>,
15 pub license: Option<String>,
16 pub path: Option<String>,
17}
18
19#[derive(Debug, Deserialize)]
21pub struct Toml {
22 pub plugin: Plugin,
23}
24
25#[derive(Debug, Deserialize)]
27pub struct Ron {
28 pub plugin: Plugin,
29}
30
31#[derive(Debug, Deserialize)]
33pub struct Json {
34 pub plugin: Plugin,
35}
36
37pub trait PluginManager {
38 fn use_plugin(&self, f: impl Fn(Plugin));
39}
40
41impl PluginManager for Plugin {
43 fn use_plugin(&self, f: impl Fn(Plugin)) {
45 f(self.clone());
46 }
47}
48
49type PErr = ParseError;
51impl_parse!(Toml, |file| toml::from_str(file)
52 .map_err(|err| PErr::Format(err.into())));
53impl_parse!(Ron, |file| ron::from_str(file)
54 .map_err(|err| PErr::Format(err.into())));
55impl_parse!(Json, |file| serde_json::from_str(file)
56 .map_err(|err| PErr::Format(err.into())));