Skip to main content

Real

Struct Real 

Source
pub struct Real(/* private fields */);
Expand description

A CIM Float or Decimal value: the number, and the spelling it arrived in.

The number is the value; the spelling is how one document happened to write it. They are kept apart for the same reason Mrid keeps a UUID apart from its spelling, and the consequences are the same shape: two Reals that denote one number are equal whatever they were written as, so a difference between two model states never reports a change that is only a reformatting — while a re-export still reproduces the document it read.

It matters because published models are full of forms no formatter would choose. The CGMES 3.0 conformity corpus writes 2.62637E-05, 0e+000 and 250.000000; rendering those as 0.0000262637, 0 and 250 re-exports a numerically identical model as a textually different file, which is what a receiving system diffs. ENTSO-E’s RDF-Syntax User Guide is explicit that engineering notation is chosen deliberately — from CIM18 active power travels as -90E6 rather than as -90000000 precisely to carry the producer’s precision — so a number’s spelling is information, not noise.

A spelling is kept only when it is a conforming lexical form for the primitive it was read as. The reader accepts 1,5 and 1.5D+3 from files that deviate (Value::parse_primitive), and reproducing those would propagate a defect into output this crate promises is valid; those are repaired to the canonical form, which is the same stance the header takes on a malformed urn:uuid:.

Implementations§

Source§

impl Real

Source

pub fn new(value: f64) -> Real

A number with no particular spelling: it renders canonically.

Source

pub fn from_document(value: f64, text: &str, prim: Primitive) -> Real

A number as a document wrote it.

The text is kept only when it differs from what this crate would write anyway and is a conforming lexical form for prim — so a value that was already canonical costs nothing, and a deviating one is repaired rather than echoed.

Source

pub fn get(&self) -> f64

Source

pub fn lexical(&self) -> Option<&str>

The spelling this value was read with, where it differs from the canonical form.

Source

pub fn to_lexical_as(&self, prim: Primitive) -> String

How to write it: the document’s spelling where there is one, else canonical.

Trait Implementations§

Source§

impl Clone for Real

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 Real

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for Real

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<Real> for Value

Source§

fn from(r: Real) -> Value

Converts to this type from the input type.
Source§

impl From<f64> for Real

Source§

fn from(value: f64) -> Real

Converts to this type from the input type.
Source§

impl PartialEq for Real

Equality is the number. The spelling is not part of the value, so 1.0 read from one file equals 1 computed in memory — which is what keeps crate::diff from reporting a change where a producer only changed its formatter.

It is f64 equality, so NaN equals nothing, itself included. CIM has no use for one and no published model contains one, but a difference computed over a model that does will report that value as changed on every run.

Source§

fn eq(&self, other: &Real) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Forget for Real

§

impl Freeze for Real

§

impl Move for Real

§

impl RefUnwindSafe for Real

§

impl Send for Real

§

impl Sync for Real

§

impl Unpin for Real

§

impl UnsafeUnpin for Real

§

impl UnwindSafe for Real

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.