Skip to main content

Mrid

Struct Mrid 

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

A master resource identifier.

Identifiers that denote a UUID are stored as 16 raw bytes together with the spelling they arrived in; anything else is kept as text. Either way the decoration CIM/XML puts around an identifier — a leading #, a leading _, a urn:uuid: prefix — is stripped on parse, so _abc, #_abc and urn:uuid:abc all denote the same object.

Non-conforming identifiers are stripped too, so rdf:ID="_X" and rdf:resource="#_X" still join.

§Spelling is remembered, identity is not spelled

Two Mrids denoting the same UUID are equal, hash alike and order alike whatever spelling they arrived in. The spelling is kept only for re-export: Mrid::to_rdf_id echoes it, while Mrid::canonical and Mrid::to_urn always give the hyphenated form RFC 4122 defines.

Implementations§

Source§

impl Mrid

Source

pub fn parse(raw: &str) -> Mrid

Parse an identifier in any of the forms CIM/XML uses.

Accepts <uuid>, _<uuid>, #_<uuid>, #<uuid> and urn:uuid:<uuid> in either the hyphenated or the compact spelling, as well as arbitrary strings (kept verbatim, reported by Mrid::form as MridForm::Opaque).

An absolute IRI whose fragment is a UUID (http://host/doc#_<uuid>, written for cross-document references) denotes that UUID. A fragment that is not a UUID leaves the whole string opaque.

Source

pub const fn from_uuid_bytes(bytes: [u8; 16]) -> Mrid

Build from raw UUID bytes, spelled the way IEC 61970-552 requires.

Source

pub const fn nil() -> Mrid

The all-zero UUID, usable in a const or static.

Source

pub fn form(&self) -> MridForm

How this identifier was spelled.

Source

pub fn is_uuid(&self) -> bool

Whether this identifier denotes a UUID, in either spelling.

This is the question the RDF writer asks, because a UUID has a urn:uuid: IRI whether or not the document hyphenated it. Use Mrid::is_conforming for the stricter question validation asks.

Source

pub fn is_conforming(&self) -> bool

Whether this identifier is written exactly as IEC 61970-552 requires.

Source

pub fn as_uuid_bytes(&self) -> Option<&[u8; 16]>

Raw UUID bytes, if this identifier denotes a UUID.

Source

pub fn canonical(&self) -> String

Canonical lowercase hyphenated form without decoration, e.g. 70c4656c-f7a0-….

Always the hyphenated spelling, whichever form the document used — this is the identifier’s canonical name, used for diagnostics and for urn:uuid: IRIs. Non-conforming identifiers are returned verbatim.

Source

pub fn as_written(&self) -> String

The identifier as the document spelled it, without decoration.

Differs from Mrid::canonical for a UUID a producer wrote without hyphens or in upper case — both of which the published CGMES 2.4.15 boundary sets do.

Source

pub fn to_rdf_id(&self) -> String

The rdf:ID form: a leading underscore, as mandated for locally defined objects.

The underscore is added for non-UUID identifiers too, since an NCName may not begin with a digit. The identifier keeps the spelling it was read with.

Not every identifier this crate can hold has such a form: see Mrid::form_in_xml.

Source

pub fn form_in_xml(&self) -> IdentifierForm

Which RDF/XML serializations this identifier can carry.

A UUID always answers IdentifierForm::Name. A non-conforming identifier, kept verbatim (see MridForm), may be neither an NCName nor an IRI: rdf:ID="_http://host/EQ.xml#Sub1" is well-formed XML but invalid RDF/XML.

Source

pub fn to_rdf_resource(&self) -> String

The rdf:resource form for a same-document reference: #_<uuid>.

Source

pub fn to_rdf_reference(&self) -> String

The value to write into rdf:resource or rdf:about, in a form RDF/XML accepts.

Same as Mrid::to_rdf_resource for every name-form identifier (all conforming input). An absolute-IRI identifier is written as itself, since #_http://…#Sub1 is not an IRI reference.

Source

pub fn to_urn(&self) -> String

The urn:uuid: form used by md:FullModel identifiers and by RDF subjects.

Always hyphenated (RFC 4122, RFC 8141). A non-UUID identifier is returned as-is.

Source

pub fn new_v5(namespace: &Mrid, name: &[u8]) -> Mrid

Derive a name-based UUID (RFC 4122 version 5) from a namespace and a name.

Deterministic: the same namespace and name always give the same identifier, with no random source or extra dependency.

let ns = Mrid::parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8"); // RFC 4122 DNS namespace
let a = Mrid::new_v5(&ns, b"MicroGrid/EQ");
assert_eq!(a, Mrid::new_v5(&ns, b"MicroGrid/EQ"));
assert_ne!(a, Mrid::new_v5(&ns, b"MicroGrid/SSH"));
assert!(a.is_conforming());

Trait Implementations§

Source§

impl Clone for Mrid

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 Mrid

Source§

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

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

impl Display for Mrid

Source§

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

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

impl Eq for Mrid

Source§

impl From<&str> for Mrid

Source§

fn from(s: &str) -> Mrid

Converts to this type from the input type.
Source§

impl From<Mrid> for Value

Source§

fn from(m: Mrid) -> Value

Converts to this type from the input type.
Source§

impl Hash for Mrid

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Mrid

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Mrid

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Mrid

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl Forget for Mrid

§

impl Freeze for Mrid
where *const str is !null: Freeze, PhantomData<str>: Freeze,

§

impl Move for Mrid

§

impl RefUnwindSafe for Mrid

§

impl Send for Mrid
where BoxRaw<str>: Send,

§

impl Sync for Mrid
where BoxRaw<str>: Sync,

§

impl Unpin for Mrid
where Box<str>: Unpin,

§

impl UnsafeUnpin for Mrid

§

impl UnwindSafe for Mrid
where BoxRaw<str>: UnwindSafe,

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.