pub enum Value {
Boolean(bool),
Integer(i64),
Float(Real),
Text(Box<str>),
Enum(EnumValueId),
Reference(Mrid),
Compound(Box<Compound>),
}Expand description
The value of a single attribute occurrence.
CIM datatypes (Resistance, ActivePower, …) serialize as their underlying
primitive, so they are represented by Value::Float and friends; the unit and
multiplier are schema constants recoverable from the attribute’s
DatatypeDef.
Variants§
Boolean(bool)
Integer(i64)
Float(Real)
Text(Box<str>)
Strings, dates, times and durations; CIM keeps these in their lexical form.
Enum(EnumValueId)
An enumeration literal.
Reference(Mrid)
A reference to another object, by mRID.
Compound(Box<Compound>)
An inline structured value with no identity of its own.
Boxed because compounds are rare — four types in all of CGMES 3.0 — and a
Compound inline would triple the size of every value in the model.
Implementations§
Source§impl Value
impl Value
pub fn as_bool(&self) -> Option<bool>
pub fn as_i64(&self) -> Option<i64>
pub fn as_f64(&self) -> Option<f64>
pub fn as_str(&self) -> Option<&str>
pub fn as_enum(&self) -> Option<EnumValueId>
pub fn as_reference(&self) -> Option<&Mrid>
pub fn as_compound(&self) -> Option<&Compound>
Sourcepub fn to_lexical(&self) -> Option<String>
pub fn to_lexical(&self) -> Option<String>
Render in the lexical form CIM/XML uses for element text.
Only meaningful for values serialized as text; enumerations, references and
compounds have their own serializations and return None.
Sourcepub fn to_lexical_as(&self, prim: Primitive) -> Option<String>
pub fn to_lexical_as(&self, prim: Primitive) -> Option<String>
Render in the lexical form prim permits.
Only one primitive is fussier than Value::to_lexical: xsd:decimal’s lexical
space has no exponent notation, while xsd:float’s does and needs it — Rust’s
plain float formatting would otherwise render 1.5e300 as 301 digits. Decimals are
therefore always written out in full, which is bounded in practice because the
values CIM types as Decimal are money and per-unit quantities.
Sourcepub fn fits(&self, prim: Primitive) -> bool
pub fn fits(&self, prim: Primitive) -> bool
Whether this value can serve an attribute declared as prim.
The single definition of that question, shared by
validate — which reports a mismatch — and by the RDF writer,
which has to decide whether to label the literal with the declared type or with
the one the value actually has.
Two allowances are deliberate. An integer serves a float or decimal, because
1 is a perfectly good float and CIM/XML gives no way to say otherwise. And dates,
times and durations are kept in their lexical form by design, so text serves them.
Sourcepub fn shape(&self) -> &'static str
pub fn shape(&self) -> &'static str
A one-word description of what this value is, for diagnostics.
Sourcepub fn parse_primitive(
prim: Primitive,
text: &str,
) -> Result<Value, ParseValueError>
pub fn parse_primitive( prim: Primitive, text: &str, ) -> Result<Value, ParseValueError>
Parse element text according to the attribute’s primitive type.