diff --git a/src/schema/resource_complete_serialisation.rs b/src/schema/resource_complete_serialisation.rs deleted file mode 100644 index e074110..0000000 --- a/src/schema/resource_complete_serialisation.rs +++ /dev/null @@ -1,112 +0,0 @@ -use crate::schema::resource::{Link, Resource}; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; - -/// Same as `Resource`, but doesn't have any of the skip_serializing_if fields and options set so the structure is more friendly to editing through the `editor` command -#[derive(Serialize, Deserialize)] -pub struct ResourceComplete { - subject: String, - aliases: Vec, - properties: HashMap>, - links: Vec, -} - -impl ResourceComplete { - pub fn from_resource(value: Resource) -> Self { - let Resource { - subject, - aliases, - properties, - links, - } = value; - Self { - subject, - aliases: aliases.unwrap_or_default(), - properties: properties.unwrap_or_default(), - links: links - .map(|vec| vec.into_iter().map(LinkComplete::from_link).collect()) - .unwrap_or_default(), - } - } - - pub fn into_resource(self) -> Resource { - let ResourceComplete { - subject, - aliases, - properties, - links, - } = self; - Resource { - subject, - aliases: if aliases.is_empty() { - None - } else { - Some(aliases) - }, - properties: if properties.is_empty() { - None - } else { - Some(properties) - }, - links: if links.is_empty() { - None - } else { - Some(links.into_iter().map(LinkComplete::into_link).collect()) - }, - } - } -} - -/// Same as `Link`, but doesn't have any of the skip_serializing_if fields set so the structure is more friendly to editing through the `editor` command -#[derive(Serialize, Deserialize)] -pub struct LinkComplete { - rel: String, - media_type: Option, - href: Option, - titles: HashMap, - properties: HashMap>, -} - -impl LinkComplete { - fn from_link(value: Link) -> Self { - let Link { - rel, - media_type, - href, - titles, - properties, - } = value; - Self { - rel, - media_type, - href, - titles: titles.unwrap_or_default(), - properties: properties.unwrap_or_default(), - } - } - - fn into_link(self) -> Link { - let LinkComplete { - rel, - media_type, - href, - titles, - properties, - } = self; - Link { - rel, - media_type, - href, - titles: if titles.is_empty() { - None - } else { - Some(titles) - }, - properties: if properties.is_empty() { - None - } else { - Some(properties) - }, - } - } -}