pub struct Element { /* private fields */ }Expand description
One decoded CIM object: its class, its mRID, and its fields as written.
Every family decodes into this one type. The fields are the document’s
own, keyed by Class.attr (the XML element’s local name), with values
unparsed: what a class declares lives in its ClassDef, not in a
generated type, so an attribute the class does not declare and a value
that does not parse are kept rather than dropped.
Implementations§
Source§impl Element
impl Element
pub fn new(class: &'static ClassDef, mrid: String) -> Self
pub fn with_fields( class: &'static ClassDef, mrid: String, fields: FieldMap, ) -> Self
pub fn class(&self) -> &'static ClassDef
Sourcepub fn types(&self) -> impl Iterator<Item = &'static ClassDef> + '_
pub fn types(&self) -> impl Iterator<Item = &'static ClassDef> + '_
Every class the object is typed as: its class, then any other a merged
file wrote it under (CimDataset::merge).
Sourcepub fn defined(&self) -> bool
pub fn defined(&self) -> bool
Whether some file defined the object (rdf:ID) rather than only
describing one defined elsewhere (rdf:about).
Sourcepub fn mark_described(&mut self)
pub fn mark_described(&mut self)
Record that the file only described the object (rdf:about).
pub fn mrid(&self) -> &str
Sourcepub fn type_name(&self) -> &'static str
pub fn type_name(&self) -> &'static str
Family-qualified class name, e.g. "Terminal" (CGMES) or
"nc:Contingency". This is the CimDataset::by_type key.
Sourcepub fn local_name(&self) -> &'static str
pub fn local_name(&self) -> &'static str
Bare CIM class name, without the family qualifier.
Sourcepub fn type_ns(&self) -> &'static str
pub fn type_ns(&self) -> &'static str
RDF namespace IRI of the declaring class, trailing delimiter included.
pub fn fields(&self) -> &FieldMap
pub fn duplicate_fields(&self) -> &FastSet<&'static str>
Sourcepub fn langs(&self, key: &str) -> impl Iterator<Item = &str>
pub fn langs(&self, key: &str) -> impl Iterator<Item = &str>
The xml:lang tags of key’s text values, one per value that had
one. A value written without a tag has no entry, so a field whose
values outnumber its tags has an untagged value.
Sourcepub fn add_lang(&mut self, key: &'static str, lang: &str)
pub fn add_lang(&mut self, key: &'static str, lang: &str)
Record the xml:lang of a text value just added to key.
pub fn get(&self, attr: &str) -> Option<&FieldValue>
pub fn get_str(&self, attr: &str) -> Option<&str>
pub fn get_f64(&self, attr: &str) -> Option<f64>
pub fn get_bool(&self, attr: &str) -> Option<bool>
Sourcepub fn get_refs(&self, attr: &str) -> &[String]
pub fn get_refs(&self, attr: &str) -> &[String]
Referenced MRIDs.
Always a slice, even where the schema says the association is 1:1 — CGMES has widened 1:1 to 1:many between versions, and a caller written against a slice does not have to change when that happens.
Sourcepub fn get_ref(&self, attr: &str) -> Option<&str>
pub fn get_ref(&self, attr: &str) -> Option<&str>
First referenced MRID, for associations known to be single-valued.
Sourcepub fn add_field(&mut self, key: &'static str, val: FieldValue)
pub fn add_field(&mut self, key: &'static str, val: FieldValue)
Add one value as the decoder reads it: a repeated key becomes a list
and is recorded in Element::duplicate_fields.
Sourcepub fn merge_from(&mut self, other: &Element)
pub fn merge_from(&mut self, other: &Element)
Combine another file’s view of the same object: a later scalar wins, reference lists are joined. Duplicate tracking stays per file.
Sourcepub fn to_json_value(&self) -> Value
pub fn to_json_value(&self) -> Value
{"id": mRID, "Class.attr": value, ...}: a value is a string, a
repeated one an array of strings.
Sourcepub fn from_json(
class: &'static ClassDef,
reg: &TypeRegistry,
value: &Value,
) -> Result<Self, String>
pub fn from_json( class: &'static ClassDef, reg: &TypeRegistry, value: &Value, ) -> Result<Self, String>
The inverse of Element::to_json_value. Whether a string is a
reference or text comes from the attribute’s declaration; an attribute
the class does not declare is read as text.