Struct rdftk_iri::IRI[][src]

pub struct IRI { /* fields omitted */ }

The IRI type comprised of Scheme, Authority, Path, Query, and Fragment components. Note that for most APIs the use of IRIRef is preferred over IRI directly.

Example

The following example creates a new IRI from a string, but also then uses that as a template to create an additional one. The normalize method in this example will convert the host name to lower case. The without_query method creates a new IRI with all components except the query copied over.

use rdftk_iri::{IRI, Normalize};
use std::str::FromStr;

let iri = IRI::from_str(
    "https://john.doe@www.EXAMPLE.com:123/forum/questions/?tag=networking&order=newest#top",
).unwrap();

let new_uri = iri.normalize().unwrap().without_query();

Definitions (from Wikipedia)

Each URI begins with a scheme name that refers to a specification for assigning identifiers within that scheme. As such, the URI syntax is a federated and extensible naming system wherein each scheme’s specification may further restrict the syntax and semantics of identifiers using that scheme. The URI generic syntax is a superset of the syntax of all URI schemes. It was first defined in RFC 2396, and finalized in RFC 3986.

The URI generic syntax consists of a hierarchical sequence of five components:[8]

URI = scheme:[//authority]path[?query][#fragment]

where the authority component divides into three subcomponents:

authority = [userinfo@]host[:port]

The URI comprises:

  • A non-empty scheme component followed by a colon (:), consisting of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus (+), period (.), or hyphen (-). Although schemes are case-insensitive, the canonical form is lowercase and documents that specify schemes must do so with lowercase letters. Examples of popular schemes include http, https, ftp, mailto, file, data, and irc. URI schemes should be registered with the Internet Assigned Numbers Authority (IANA), although non-registered schemes are used in practice.
  • An optional authority component preceded by two slashes (//), comprising:
    • An optional userinfo subcomponent that may consist of a user name and an optional password preceded by a colon (:), followed by an at symbol (@). Use of the format username:password in the userinfo subcomponent is deprecated for security reasons. Applications should not render as clear text any data after the first colon (:) found within a userinfo subcomponent unless the data after the colon is the empty string (indicating no password).
    • A host subcomponent, consisting of either a registered name (including but not limited to a hostname), or an IP address. IPv4 addresses must be in dot-decimal notation, and IPv6 addresses must be enclosed in brackets ([]).
    • An optional port subcomponent preceded by a colon (:).
  • A path component, consisting of a sequence of path segments separated by a slash (/). A path is always defined for a URI, though the defined path may be empty (zero length). A segment may also be empty, resulting in two consecutive slashes (//) in the path component. A path component may resemble or map exactly to a file system path, but does not always imply a relation to one. If an authority component is present, then the path component must either be empty or begin with a slash (/). If an authority component is absent, then the path cannot begin with an empty segment, that is with two slashes (//), as the following characters would be interpreted as an authority component. The final segment of the path may be referred to as a ‘slug’.
  • An optional query component preceded by a question mark (?), containing a query string of non-hierarchical data. Its syntax is not well defined, but by convention is most often a sequence of attribute–value pairs separated by a delimiter.
  • An optional fragment component preceded by a hash (#). The fragment contains a fragment identifier providing direction to a secondary resource, such as a section heading in an article identified by the remainder of the URI. When the primary resource is an HTML document, the fragment is often an id attribute of a specific element, and web browsers will scroll this element into view.

Strings of data octets within a URI are represented as characters. Permitted characters within a URI are the ASCII characters[*] for the lowercase and uppercase letters of the modern English alphabet, the Arabic numerals, hyphen, period, underscore, and tilde. Octets represented by any other character must be percent-encoded.

Of the ASCII character set, the characters : / ? # [ ] @ are reserved for use as delimiters of the generic URI components and must be percent-encoded – for example, %3F for a question mark. The characters ! $ & ’ ( ) * + , ; = are permitted by generic URI syntax to be used unencoded in the user information, host, and path as delimiters. Additionally, : and @ may appear unencoded within the path, query, and fragment; and ? and / may appear unencoded as data within the query or fragment.

[*] While URIs are limited to a subset of the ASCII character set, IRIs may additionally contain most characters from the Universal Character Set (Unicode/ISO 10646), including Chinese, Japanese, Korean, and Cyrillic characters.

Implementations

impl IRI[src]

pub fn new(path: &Path) -> Self[src]

Create a new IRI with only the specified path, this is a valid relative value – see is_absolute.

This is also provided as an implementation of From<&Path> and From<Path> for IRI.

Example

use rdftk_iri::{IRI, Path};
use std::str::FromStr;

let iri = IRI::new(
    &Path::from_str("/forum/questions/").unwrap()
);

pub fn new_file(path: &PathBuf) -> IriResult<Self>[src]

Construct a new IRI with the “file” scheme and the provided file system path.

This is also provided as an implementation of TryFrom<&PathBuf> and TryFrom<PathBuf> for IRI if the “path_iri” feature has been enabled.

Example

use rdftk_iri::IRI;
use std::path::PathBuf;

let iri = IRI::new_file(&PathBuf::from("Documents/test-plan.md")).unwrap();

This results in the IRI file://Documents/test-plan.md.

pub fn new_name(
    namespace_identifier: &str,
    namespace_specific_string: &str
) -> IriResult<Self>
[src]

Construct a new URN IRI with the given namespace identifier and namespace-specific string.

Example

use rdftk_iri::IRI;

let iri = IRI::new_name("uuid", "f3b4958c-52a1-11e7-802a-010203040506").unwrap();

This results in the IRI urn:uuid:f3b4958c-52a1-11e7-802a-010203040506.

pub fn with_new_path(&self, path: Path) -> Self[src]

Return a new IRI as a copy of self with the path component replaced by the provided path value.

pub fn without_path(&self) -> Self[src]

Return a new IRI as a copy of self with the path component replaced with the value of Path::default().

pub fn with_new_query(&self, query: Query) -> Self[src]

Return a new IRI as a copy of self with the query component replaced by the provided query value.

pub fn without_query(&self) -> Self[src]

Return a new IRI as a copy of self with the query component removed.

pub fn with_new_fragment(&self, fragment: Fragment) -> Self[src]

Return a new IRI as a copy of self with the fragment component replaced by the provided fragment value.

pub fn without_fragment(&self) -> Self[src]

Return a new IRI as a copy of self with the fragment component removed.

pub fn resolve(&self, relative: &IRI) -> IriResult<Self>[src]

Resolves the IRI value relative using self as the base.

If the given URI is already absolute, or if this URI is opaque, then the given URI is returned. Otherwise this method constructs a new hierarchical URI in a manner consistent with RFC 2396, §5.2;.

pub fn relativize(&self, _other: &IRIRef) -> IriResult<Self>[src]

Relativizes the IRI other against this IRI.

The relativization of the IRI other against this IRI is computed as follows:

  1. If either this IRI or the given IRI are opaque, or if the scheme and authority components of the two IRIs are not identical, or if the path of this IRI is not a prefix of the path of the given IRI, then the given IRI is returned.
  2. Otherwise a new relative hierarchical IRI is constructed with query and fragment components taken from the given IRI and with a path component computed by removing this IRI’s path from the beginning of the given IRI’s path.

pub fn is_absolute(&self) -> bool[src]

Returns true if this is an absolute IRI, else false. An IRI is absolute if, and only if, it has a scheme component and does not have a fragment component.

Examples

assert!(IRI::from_str("mailto:a@b.com").unwrap().is_absolute());
assert!(IRI::from_str("http://example.com").unwrap().is_absolute());
assert!(IRI::from_str("http://example.com/path").unwrap().is_absolute());
assert!(IRI::from_str("scheme://example.com").unwrap().is_absolute());
assert!(IRI::from_str("scheme:example.com").unwrap().is_absolute());
assert!(IRI::from_str("scheme:example.com/path").unwrap().is_absolute());

assert!(!IRI::from_str("//example.com/path#foo").unwrap().is_absolute());
assert!(!IRI::from_str("http://example.com/path#foo").unwrap().is_absolute());
assert!(!IRI::from_str("scheme:example.com#foo").unwrap().is_absolute());
assert!(!IRI::from_str("path").unwrap().is_absolute());
assert!(!IRI::from_str("/path").unwrap().is_absolute());

pub fn is_relative_reference(&self) -> bool[src]

Returns true if this is a relative IRI reference, else false. An IRI is a relative reference if, and only if, it does not have a scheme component.

Examples

assert!(IRI::from_str("//example.com/path#foo").unwrap().is_relative_reference());
assert!(IRI::from_str("path").unwrap().is_relative_reference());
assert!(IRI::from_str("/path").unwrap().is_relative_reference());

assert!(!IRI::from_str("mailto:a@b.com").unwrap().is_relative_reference());
assert!(!IRI::from_str("http://example.com").unwrap().is_relative_reference());
assert!(!IRI::from_str("http://example.com/path").unwrap().is_relative_reference());
assert!(!IRI::from_str("scheme://example.com").unwrap().is_relative_reference());
assert!(!IRI::from_str("scheme:example.com").unwrap().is_relative_reference());
assert!(!IRI::from_str("scheme:example.com/path").unwrap().is_relative_reference());
assert!(!IRI::from_str("http://example.com/path#foo").unwrap().is_relative_reference());
assert!(!IRI::from_str("scheme:example.com#foo").unwrap().is_relative_reference());

pub fn is_opaque(&self) -> bool[src]

Returns true if this is an opaque IRI, else false. An IRI is opaque if, and only if, i t is absolute and its scheme-specific part does not begin with a slash character (‘/’). An opaque IRI has a scheme, a scheme-specific part, and possibly a fragment; all other components are undefined.

Examples

assert!(IRI::from_str("mailto:a@b.com").unwrap().is_opaque());
assert!(IRI::from_str("scheme:example.com").unwrap().is_opaque());
assert!(IRI::from_str("scheme:example.com/path").unwrap().is_opaque());

assert!(!IRI::from_str("http://example.com").unwrap().is_opaque());
assert!(!IRI::from_str("http://example.com/path").unwrap().is_opaque());
assert!(!IRI::from_str("scheme://example.com").unwrap().is_opaque());
assert!(!IRI::from_str("path").unwrap().is_opaque());
assert!(!IRI::from_str("/path").unwrap().is_opaque());

pub fn has_scheme(&self) -> bool[src]

Return true if this IRI include a scheme, else false.

pub fn scheme(&self) -> &Option<Scheme>[src]

Return the current value of the scheme component.

pub fn scheme_specific_part(&self) -> String[src]

Return the scheme-specific part of the IRI, basically any part of the IRI that isn’t the scheme itself.

pub fn has_authority(&self) -> bool[src]

Return true if this IRI include a authority, else false.

pub fn authority(&self) -> &Option<Authority>[src]

Return the current value of the authority component.

pub fn has_path(&self) -> bool[src]

Return true if this IRI include a path, else false.

pub fn path(&self) -> &Path[src]

Return the current value of the path component.

pub fn has_query(&self) -> bool[src]

Return true if this IRI include a query, else false.

pub fn query(&self) -> &Option<Query>[src]

Return the current value of the query component.

pub fn has_fragment(&self) -> bool[src]

Return true if this IRI include a fragment, else false.

pub fn fragment(&self) -> &Option<Fragment>[src]

Return the current value of the fragment component.

pub fn set_scheme(&mut self, scheme: Option<Scheme>)[src]

Set the value of the scheme component.

pub fn set_authority(&mut self, authority: Option<Authority>)[src]

Set the value of the authority component.

pub fn set_path(&mut self, path: Path)[src]

Set the value of the path component.

pub fn set_query(&mut self, query: Option<Query>)[src]

Set the value of the query component.

pub fn set_fragment(&mut self, fragment: Option<Fragment>)[src]

Set the value of the fragment component.

Trait Implementations

impl Clone for IRI[src]

impl Debug for IRI[src]

impl Default for IRI[src]

impl Display for IRI[src]

impl Eq for IRI[src]

impl From<&'_ Path> for IRI[src]

impl From<Path> for IRI[src]

impl FromStr for IRI[src]

type Err = IriError

The associated error which can be returned from parsing.

impl Hash for IRI[src]

impl Normalize for IRI[src]

impl PartialEq<IRI> for IRI[src]

impl StructuralEq for IRI[src]

impl StructuralPartialEq for IRI[src]

impl TryFrom<&'_ PathBuf> for IRI[src]

type Error = IriError

The type returned in the event of a conversion error.

impl TryFrom<&'_ Uuid> for IRI[src]

type Error = IriError

The type returned in the event of a conversion error.

impl TryFrom<&'_ mut IriBuilder> for IRI[src]

type Error = IriError

The type returned in the event of a conversion error.

impl TryFrom<PathBuf> for IRI[src]

type Error = IriError

The type returned in the event of a conversion error.

impl TryFrom<Uuid> for IRI[src]

type Error = IriError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for IRI

impl Send for IRI

impl Sync for IRI

impl Unpin for IRI

impl UnwindSafe for IRI

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.