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
impl Mrid
Sourcepub fn parse(raw: &str) -> Mrid
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.
Sourcepub const fn from_uuid_bytes(bytes: [u8; 16]) -> Mrid
pub const fn from_uuid_bytes(bytes: [u8; 16]) -> Mrid
Build from raw UUID bytes, spelled the way IEC 61970-552 requires.
Sourcepub fn is_uuid(&self) -> bool
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.
Sourcepub fn is_conforming(&self) -> bool
pub fn is_conforming(&self) -> bool
Whether this identifier is written exactly as IEC 61970-552 requires.
Sourcepub fn as_uuid_bytes(&self) -> Option<&[u8; 16]>
pub fn as_uuid_bytes(&self) -> Option<&[u8; 16]>
Raw UUID bytes, if this identifier denotes a UUID.
Sourcepub fn canonical(&self) -> String
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.
Sourcepub fn as_written(&self) -> String
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.
Sourcepub fn to_rdf_id(&self) -> String
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.
Sourcepub fn form_in_xml(&self) -> IdentifierForm
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.
Sourcepub fn to_rdf_resource(&self) -> String
pub fn to_rdf_resource(&self) -> String
The rdf:resource form for a same-document reference: #_<uuid>.
Sourcepub fn to_rdf_reference(&self) -> String
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.
Sourcepub fn to_urn(&self) -> String
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.
Sourcepub fn new_v5(namespace: &Mrid, name: &[u8]) -> Mrid
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§
impl Eq for Mrid
Source§impl Ord for Mrid
impl Ord for Mrid
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Auto Trait Implementations§
impl Forget for Mrid
impl Freeze for Mrid
impl Move for Mrid
impl RefUnwindSafe for Mrid
impl Send for Mrid
impl Sync for Mrid
impl Unpin for Mrid
impl UnsafeUnpin for Mrid
impl UnwindSafe for Mridwhere
BoxRaw<str>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.