diff --git a/examples/bffh.dhall b/examples/bffh.dhall index 4a57c51..249f473 100644 --- a/examples/bffh.dhall +++ b/examples/bffh.dhall @@ -33,7 +33,8 @@ ] , machines = { Testmachine = - { description = Some "A test machine" + { description = "A test machine" + , wiki = "test" , disclose = "lab.test.read" , manage = "lab.test.admin" , name = "MachineA" @@ -41,7 +42,7 @@ , write = "lab.test.write" }, Another = - { description = Some "Another test machine" + { wiki = "test_another" , disclose = "lab.test.read" , manage = "lab.test.admin" , name = "Another" @@ -49,7 +50,7 @@ , write = "lab.test.write" }, Yetmore = - { description = Some "Yet more test machines" + { description = "Yet more test machines" , disclose = "lab.test.read" , manage = "lab.test.admin" , name = "Yetmore" diff --git a/src/machine.rs b/src/machine.rs index 255c669..9bd53c7 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -352,6 +352,7 @@ impl Inner { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] /// A description of a machine /// /// This is the struct that a machine is serialized to/from. @@ -359,11 +360,12 @@ impl Inner { pub struct MachineDescription { /// The name of the machine. Doesn't need to be unique but is what humans will be presented. pub name: String, + /// An optional description of the Machine. + #[serde(default, skip_serializing_if = "Option::is_none", deserialize_with = "deser_option")] pub description: Option, - #[serde(default)] - #[serde(flatten)] + #[serde(default, skip_serializing_if = "Option::is_none", deserialize_with = "deser_option")] pub wiki: Option, /// The permission required @@ -371,6 +373,12 @@ pub struct MachineDescription { pub privs: access::PrivilegesBuf, } +fn deser_option<'de, D, T>(d: D) -> std::result::Result, D::Error> + where D: serde::Deserializer<'de>, T: serde::Deserialize<'de>, +{ + Ok(T::deserialize(d).ok()) +} + impl MachineDescription { pub fn load_file>(path: P) -> Result> { let content = fs::read(path)?;