siteslib/jsonb/
details.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use serde::{Deserialize, Serialize};

use crate::enums::content_type::ContentType;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Details {
    #[serde(rename(serialize = "type", deserialize = "type"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content_type: Option<ContentType>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<String>,
}

impl Details {
    pub fn normalize(&self) -> Self {
        Self {
            content_type: self.content_type.clone(),
            content: if self.content.is_some() {
                Option::from(self.content.clone().unwrap().replace(r#"""#, "'"))
            } else {
                None
            },
        }
    }
}