assemblylift_core_entity/
package.rs1use serde::Deserialize;
2
3#[derive(Deserialize)]
4pub struct EntityManifest {
5 pub entity: ManifestHeader,
6 pub fields: Vec<Field>,
7 pub caps: Option<Vec<Capability>>,
8 pub policies: Option<Vec<Policy>>,
9}
10
11impl EntityManifest {
12 pub fn read(path: &std::path::PathBuf) -> Result<Self, std::io::Error> {
13 match std::fs::read_to_string(path) {
14 Ok(contents) => Ok(Self::from(contents)),
15 Err(why) => Err(std::io::Error::new(std::io::ErrorKind::Other, why.to_string())),
16 }
17 }
18}
19
20impl From<String> for EntityManifest {
21 fn from(string: String) -> Self {
22 match toml::from_str(&string) {
23 Ok(manifest) => manifest,
24 Err(why) => panic!("error parsing EntityManifest: {}", why.to_string()),
25 }
26 }
27}
28
29#[derive(Deserialize)]
30pub struct ManifestHeader {
31 pub name: String,
32}
33
34#[derive(Deserialize)]
35pub struct Field {
36 pub name: String,
37 pub r#type: String,
38 pub attributes: Option<Vec<String>>,
39}
40
41#[derive(Deserialize)]
42pub struct Capability {
43 pub action: String,
44}
45
46#[derive(Deserialize)]
47pub struct Policy {
48 pub name: String,
49 pub r#type: String,
50 pub file: Option<String>,
51 pub from: Option<String>,
52}