Struct iref::Iri[][src]

pub struct Iri<'a>(_);
Expand description

IRI slice.

Wrapper around a borrowed bytes slice representing an IRI. An IRI can be seen as an IRI-reference with a defined Scheme. All methods of IriRef are available from this type, however the scheme method is redefined to always return some scheme.

Example

let iri = Iri::new("https://www.rust-lang.org/foo/bar?query#frag")?;

println!("scheme: {}", iri.scheme()); // note the absence of `unwrap` here since
                                      // the scheme is always defined in an IRI.
println!("authority: {}", iri.authority().unwrap());
println!("path: {}", iri.path());
println!("query: {}", iri.query().unwrap());
println!("fragment: {}", iri.fragment().unwrap());

Implementations

Create a new IRI slice from a bytes slice.

This may fail if the source slice is not UTF-8 encoded, or is not a valid IRI.

Create a new IRI from a string.

This replaces a std::str::FromStr implementation as the trait is incompatiple with the result storing the input which Iri does.

Convert the slice-like Iri into the owned version IriBuf.

Build an IRI from an IRI reference.

Get an IriRef out of this IRI.

An IRI is always a valid IRI-reference.

Get the scheme of the IRI.

Contrarily to IriRef, the scheme of an IRI is always defined.

Methods from Deref<Target = IriRef<'a>>

Get the underlying parsing data.

Get the length is the IRI-reference, in bytes.

Returns a reference to the byte representation of the IRI-reference.

Get the IRI-reference as a string slice.

Get the IRI-reference as a percent-encoded string slice.

Get the scheme of the IRI-reference.

The scheme is located at the very begining of the IRI-reference and delimited by an ending :.

Example

assert_eq!(IriRef::new("foo://example.com:8042").unwrap().scheme().unwrap(), "foo");
assert_eq!(IriRef::new("//example.com:8042").unwrap().scheme(), None);

Get the authority of the IRI-reference.

The authority is delimited by the // string, after the scheme.

Example

assert_eq!(IriRef::new("foo://example.com:8042").unwrap().authority().unwrap().host(), "example.com");
assert_eq!(IriRef::new("foo:").unwrap().authority(), None);

Get the path of the IRI-reference.

The path is located just after the authority. It is always defined, even if empty.

Example

assert_eq!(IriRef::new("foo:/a/b/c?query").unwrap().path(), "/a/b/c");
assert!(IriRef::new("foo:#fragment").unwrap().path().is_empty());

Get the query of the IRI-reference.

The query part is delimited by the ? character after the path.

Example

assert_eq!(IriRef::new("//example.org?query").unwrap().query().unwrap(), "query");
assert!(IriRef::new("//example.org/foo/bar#fragment").unwrap().query().is_none());

Get the fragment of the IRI-reference.

The fragment part is delimited by the # character after the query.

Example

assert_eq!(IriRef::new("//example.org#foo").unwrap().fragment().unwrap(), "foo");
assert!(IriRef::new("//example.org").unwrap().fragment().is_none());

Resolve the IRI reference against the given base IRI.

Return the resolved IRI. See the IriRefBuf::resolve method for more informations about the resolution process.

Get the suffix of this IRI reference, if any, with regard to the given prefix IRI reference..

Returns Some((suffix, query, fragment)) if this IRI reference is of the form prefix/suffix?query#fragment where prefix is given as parameter. Returns None otherwise. If the suffix scheme or authority is different from this path, it will return None.

See Path::suffix for more details.

The IRI reference without the file name, query and fragment.

Example

let a = IriRef::new("https://crates.io/crates/iref?query#fragment").unwrap();
let b = IriRef::new("https://crates.io/crates/iref/?query#fragment").unwrap();
assert_eq!(a.base(), "https://crates.io/crates/");
assert_eq!(b.base(), "https://crates.io/crates/iref/")

Get this IRI reference relatively to the given one.

Example

let a = IriRef::new("https://crates.io/").unwrap();
let b = IriRef::new("https://crates.io/crates/iref").unwrap();
let c = IriRef::new("https://crates.io/crates/json-ld").unwrap();
assert_eq!(b.relative_to(a), "crates/iref");
assert_eq!(a.relative_to(b), "../");
assert_eq!(b.relative_to(c), "iref");
assert_eq!(c.relative_to(b), "json-ld");

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.