Skip to main content

Schema

Struct Schema 

Source
pub struct Schema {
    pub vintage: &'static str,
    pub namespaces: &'static [NamespaceDef],
    pub profiles: &'static [ProfileDef],
    pub classes: &'static [ClassDef],
    pub attributes: &'static [AttrDef],
    pub enums: &'static [EnumDef],
    pub enum_values: &'static [EnumValueDef],
    pub datatypes: &'static [DatatypeDef],
    pub class_index: &'static [(u16, &'static str, ClassId)],
    pub attr_index: &'static [(u16, &'static str, AttrId)],
    pub enum_value_index: &'static [(u16, &'static str, EnumValueId)],
}
Expand description

A complete CIM schema vintage.

Fields§

§vintage: &'static str

Vintage key, e.g. cgmes3.

§namespaces: &'static [NamespaceDef]§profiles: &'static [ProfileDef]§classes: &'static [ClassDef]§attributes: &'static [AttrDef]§enums: &'static [EnumDef]§enum_values: &'static [EnumValueDef]§datatypes: &'static [DatatypeDef]§class_index: &'static [(u16, &'static str, ClassId)]

(ns index, local name) sorted, for binary-search lookup of classes.

§attr_index: &'static [(u16, &'static str, AttrId)]

(ns index, qualified name) sorted, for attribute lookup.

§enum_value_index: &'static [(u16, &'static str, EnumValueId)]

(ns index, qualified name) sorted, for enum literal lookup.

Implementations§

Source§

impl Schema

Source

pub fn class(&self, id: ClassId) -> &'static ClassDef

Source

pub fn attr(&self, id: AttrId) -> &'static AttrDef

Source

pub fn enumeration(&self, id: EnumId) -> &'static EnumDef

Source

pub fn enum_value(&self, id: EnumValueId) -> &'static EnumValueDef

Source

pub fn datatype(&self, id: DatatypeId) -> &'static DatatypeDef

Source

pub fn profile(&self, id: ProfileId) -> &'static ProfileDef

Source

pub fn namespace(&self, id: NsId) -> &'static NamespaceDef

Source

pub fn ns_id(&self, iri: &str) -> Option<NsId>

Source

pub fn profile_by_keyword(&self, keyword: &str) -> Option<ProfileId>

Source

pub fn profile_by_iri(&self, iri: &str) -> Option<ProfileId>

Resolve the md:Model.profile IRI written in an instance file header.

The trailing version segment is ignored so that, for example, a file declaring .../CoreEquipment-EU/3.0 still resolves when the schema knows /3.0.

Source

pub fn find_class(&self, ns: &str, local: &str) -> Option<ClassId>

Look up a class by namespace IRI and local name.

Source

pub fn class_by_name(&self, local: &str) -> Option<ClassId>

Look up a class by local name in whichever namespace declares it.

For tooling that must work across vintages without knowing their namespaces: Substation lives in CIM100 in CGMES 3.0 and in cim16 in CGMES 2.4.15, and a program that only wants to count substations should not have to spell either. Where two namespaces declare the same local name — an extension shadowing a core class — the first in namespace order wins, so Schema::find_class is the call to reach for when the distinction matters.

Source

pub fn find_attr(&self, ns: &str, qualified: &str) -> Option<AttrId>

Look up an attribute by namespace IRI and qualified name (Class.attr).

Source

pub fn find_enum_value(&self, ns: &str, qualified: &str) -> Option<EnumValueId>

Look up an enumeration literal by namespace IRI and qualified name.

Source

pub fn find_enum_value_any_ns(&self, qualified: &str) -> Option<EnumValueId>

Look up an enumeration literal by qualified name in any namespace.

Exporters do misplace these: published CGMES 2.4.15 test models write the ENTSO-E extension literal LimitTypeKind.patl under the cim namespace. The qualified name is unambiguous on its own, so the value can still be recovered — callers should report the namespace mismatch rather than accept it silently.

Source

pub fn is_a(&self, class: ClassId, ancestor: ClassId) -> bool

Whether class is ancestor or inherits from it.

Source

pub fn attr_by_label(&self, class: ClassId, label: &str) -> Option<AttrId>

Find an attribute visible on class by its short label.

Searches the class and its ancestors, most-derived first.

Source

pub fn effective_profiles( &self, attr: AttrId, provenance: ProfileMask, ) -> ProfileMask

The profiles a stored value belongs in — the single rule the writer and the per-profile coverage report share, so the report cannot drift from the export.

provenance is the profile mask recorded on the value when it was read (zero for values set programmatically). It is intersected with the profiles that actually declare the attribute, because one instance file routinely declares several profiles: a CGMES 3.0 Equipment file commonly declares both CoreEquipment and ShortCircuit, and without the intersection every value in it would be written to both exports, duplicating the whole file.

The intersection can be empty, because published files do set attributes their own header does not declare — a CGMES 2.4.15 boundary file writes Terminal.ConnectivityNode, which only the Equipment profile declares. When that happens the value goes back where it came from: the data is evidence, the vocabulary is a claim about it, and re-filing the value under a profile its source does not serve would drop it from every export. validate reports the discrepancy as Rule::AttributeNotInProfile.

Only a value with no provenance at all — one set programmatically — falls back to the attribute’s declaration, which is then the sole available answer.

Source

pub fn declaration_covers(&self, attr: AttrId, provenance: ProfileMask) -> bool

Whether a value’s source file declared a profile that declares its attribute.

False means the file under-declares its own content: it carries data belonging to a profile its md:Model.profile does not name. Published models do this — the RealGrid Equipment file carries ShortCircuit attributes while declaring only CoreEquipment — so it is a warning about the header, not a reason to lose data.

Source

pub fn match_score<'a>( &self, namespaces: impl IntoIterator<Item = &'a str>, ) -> usize

How strongly a document declaring namespaces looks like this vintage.

The number of this vintage’s classes that live in namespaces the document declares.

Weighted by class count rather than by namespace, because every namespace a schema knows holds at least one class — the 61970-552 header vocabulary puts classes in md, dm and even rdf — so presence alone discriminates nothing. Bulk does: CIM100# holds 436 classes against rdf’s one, so a CGMES 2.4.15 document scores 400 for 2.4.15 and 3 for 3.0.

Source

pub fn detect<'a>( namespaces: impl IntoIterator<Item = &'a str>, ) -> Option<&'static Schema>

The compiled-in vintage a document declaring namespaces belongs to.

CIM/XML names its vocabulary in the document — xmlns:cim="…/CIM100#" for CGMES 3.0, "…/CIM-schema-cim16#" for 2.4.15 — so the caller never has to guess, and guessing wrong is expensive: reading a 2.4.15 file against the CGMES 3.0 tables resolves no class at all and yields an empty model with one “unknown class” warning per element.

Returns None when nothing in the document points at any compiled-in vintage, which is the honest answer for a build without the matching feature.

See reader::sniff, which answers this from a document’s root element without parsing the rest.

Source

pub fn concrete_classes(&self) -> impl Iterator<Item = ClassId> + '_

Every concrete class, useful for tooling that enumerates the model.

Trait Implementations§

Source§

impl Debug for Schema

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Schema

§

impl Freeze for Schema

§

impl Move for Schema

§

impl RefUnwindSafe for Schema

§

impl Send for Schema

§

impl Sync for Schema

§

impl Unpin for Schema

§

impl UnsafeUnpin for Schema

§

impl UnwindSafe for Schema

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