Expand description
This crate provides an IriExtra
trait, Iri
, Name
, and QName
types and associated errors.
§IRI Type
The Iri
type is a wrapper around the url::Url
type, and as can be constructed in the
same manner.
§Examples
use rdftk_iri::Iri;
use std::str::FromStr;
let result = Iri::from_str(
"https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top",
).unwrap();
The IriExtra
trait provides a number of additional methods useful to the IRI as a namespace
and namespaced-name identifier.
use rdftk_iri::{Iri, IriExtra as _, Name};
use std::str::FromStr;
let namespace = Iri::from_str(
"https://example.org/ns/things#",
).unwrap();
assert!(namespace.looks_like_namespace());
let name = namespace.make_name(Name::from_str("ThisThing").unwrap()).unwrap();
assert_eq!(
name.to_string(),
"https://example.org/ns/things#ThisThing".to_string(),
);
assert_eq!(
name.namespace(),
Some(namespace),
);
assert_eq!(
name.name(),
Some(Name::from_str("ThisThing").unwrap()),
);
§Name (NCName) Type
TBD
§QName Type
Qualified names, names with the form {prefix}:{name}
are used in a number of common serialization
forms and use many of the same production rules as those for XML.
§Specification
- https://www.w3.org/TR/REC-xml-names/
- https://www.w3.org/TR/REC-xml/#NT-Name
- https://www.w3.org/2001/tag/doc/qnameids
From (1):
/* Attribute Names for Namespace Declaration */
[4] NCName ::= Name - (Char* ':' Char*) /* An XML Name, minus the ":" */
/* Qualified Name */
[7] QName ::= PrefixedName
| UnprefixedName
[8] PrefixedName ::= Prefix ':' LocalPart
[9] UnprefixedName ::= LocalPart
[10] Prefix ::= NCName
[11] LocalPart ::= NCName
From (2):
[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF]
| [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F]
| [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD]
| [#x10000-#xEFFFF]
[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F]
| [#x203F-#x2040]
[5] Name ::= NameStartChar (NameChar)*
§Example
use rdftk_iri::{Name, QName};
use std::str::FromStr;
let prefixed: QName = "prefix:name".parse().expect("parse error");
let un_prefixed: QName = "name".parse().expect("parse error");
let prefixed: QName = QName::new(
Name::new_unchecked("prefix"),
Name::new_unchecked("name"),
).unwrap();
let un_prefixed: QName = QName::new_unqualified(Name::new_unchecked("name")).unwrap();
assert!(QName::from_str("").is_err());
assert!(QName::from_str("hello world").is_err());
§Curie
Specification: https://www.w3.org/TR/curie/
safe_curie := '[' curie ']'
curie := [ [ prefix ] ':' ] reference
prefix := NCName
reference := irelative-ref (as defined in IRI)
Note that while the empty string matches the production for curie above, an empty string is NOT a valid CURIE. The CURIE prefix ‘’ is reserved for use by languages that support RDF. For this reason, the prefix ‘’ SHOULD be avoided by authors.
Structs§
- This type represents the name component of an IRI used as a namespaced identifier.
- QNames are valid identifiers with an optional prefix identifier. e.g. “
xsd:integer
”, “rdfs:Class
”, “:subPropertyOf
”.
Enums§
- Denotes an error generated by the
NameParser
’sparse_str
method. - This enum represents the different rules used to validate a string as a potential
Name
value.
Traits§
- Additional, mainly constructor functions for the
Iri
type.
Type Aliases§
- Errors reported while parsing a string into an IRI.
- The common type for IRI values used throughout the RDFtk packages.