Skip to main content

cimstructs/
URI.rs

1/// URI is a string following the rules defined by the W3C/IETF URI Planning Interest Group in a set of RFCs of which one is RFC 3305.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct URI {
4    pub id: String,
5}
6impl crate::base::CimElement for URI {
7    fn mrid(&self) -> &str { &self.id }
8    fn type_name(&self) -> &'static str { "URI" }
9    fn as_any(&self) -> &dyn std::any::Any { self }
10    fn to_json_value(&self) -> serde_json::Value {
11        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
12    }
13    fn to_block(&self) -> crate::base::RdfBlock {
14        let block = crate::base::RdfBlock {
15            type_name: "URI".to_string(),
16            mrid: self.id.clone(),
17            fields: std::collections::HashMap::new(),
18            duplicate_fields: std::collections::HashSet::new(),
19        };
20        block
21    }
22}
23
24impl URI {
25    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
26        let mut obj = Self::default();
27        obj.id.clone_from(&b.mrid);
28        obj
29    }
30}