Skip to main content

Element

Struct Element 

Source
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

Source

pub fn new(class: &'static ClassDef, mrid: String) -> Self

Source

pub fn with_fields( class: &'static ClassDef, mrid: String, fields: FieldMap, ) -> Self

Source

pub fn class(&self) -> &'static ClassDef

Source

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).

Source

pub fn mrid(&self) -> &str

Source

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.

Source

pub fn local_name(&self) -> &'static str

Bare CIM class name, without the family qualifier.

Source

pub fn type_ns(&self) -> &'static str

RDF namespace IRI of the declaring class, trailing delimiter included.

Source

pub fn fields(&self) -> &FieldMap

Source

pub fn duplicate_fields(&self) -> &FastSet<&'static str>

Source

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.

Source

pub fn add_lang(&mut self, key: &'static str, lang: &str)

Record the xml:lang of a text value just added to key.

Source

pub fn get(&self, attr: &str) -> Option<&FieldValue>

Source

pub fn get_str(&self, attr: &str) -> Option<&str>

Source

pub fn get_f64(&self, attr: &str) -> Option<f64>

Source

pub fn get_bool(&self, attr: &str) -> Option<bool>

Source

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.

Source

pub fn get_ref(&self, attr: &str) -> Option<&str>

First referenced MRID, for associations known to be single-valued.

Source

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.

Source

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.

Source

pub fn to_json_value(&self) -> Value

{"id": mRID, "Class.attr": value, ...}: a value is a string, a repeated one an array of strings.

Source

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.

Trait Implementations§

Source§

impl Clone for Element

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Element

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.