[][src]Struct sophia_term::iri::Iri

pub struct Iri<TD: TermData> { /* fields omitted */ }

An IRI reference.

Contract

Each Iri represents a valid IRI reference according to the RFC3987 either relative or absolute. This is checked by standard constructors (new and new_suffixed). On the other hand, it is the obligation of the user to ensure that invocations of *_unchecked() methods produce valid output. Note that the creation of invalid IRIs may lead to unexpected errors in other places.

Implementations

impl<TD> Iri<TD> where
    TD: TermData
[src]

pub fn new<U>(iri: U) -> Result<Self> where
    U: AsRef<str>,
    TD: From<U>, 
[src]

Return a new IRI-term from a given IRI.

It is checked if the input is either an absolute or relative IRI. If it is none of them an error is returned.

pub fn new_suffixed<U, V>(ns: U, suffix: V) -> Result<Self> where
    U: AsRef<str>,
    V: AsRef<str>,
    TD: From<U> + From<V>, 
[src]

Return a new IRI-term from a given namespace and suffix.

It is checked if the input is either an absolute or relative IRI. If it is none of them an error is returned.

Performance

In order to check if the concatenation of namespace and suffix results in a valid IRI a new String is allocated and namespace and suffix are copied into it.

pub fn new_unchecked<U>(iri: U) -> Self where
    TD: From<U>, 
[src]

Create a new IRI-term from a given IRI without checking its validity.

Pre-condition

This function conducts no checks if the resulting IRI is valid. This is a contract that is generally assumed. Breaking it could result in unexpected behavior.

However, in debug builds assertions that perform checks are enabled.

pub fn new_suffixed_unchecked<U, V>(ns: U, suffix: V) -> Self where
    TD: From<U> + From<V>, 
[src]

Create a new IRI-term from a given namespace and suffix.

Pre-conditions

It is expected that

  • the resulting IRI is valid per RFC3987,
  • suffix is not the empty string (otherwise, new_unchecked should be used instead).

This is a contract that is generally assumed. Breaking it could result in unexpected behavior. However in debug mode, assertions that perform checks are enabled.

pub fn ns(&self) -> &TD[src]

The namespace of the IRI.

If the IRI has no suffix this is the whole IRI.

pub fn suffix(&self) -> &Option<TD>[src]

The suffix of the IRI.

pub fn as_ref(&self) -> Iri<&TD>[src]

Borrow the inner contents of the IRI.

pub fn as_ref_str(&self) -> Iri<&str>[src]

Borrow the inner contents of the IRI as &str.

pub fn map<F, TD2>(self, f: F) -> Iri<TD2> where
    F: FnMut(TD) -> TD2,
    TD2: TermData
[src]

Create a new IRI by applying f to the TermData of self.

pub fn map_into<TD2>(self) -> Iri<TD2> where
    TD: Into<TD2>,
    TD2: TermData
[src]

Maps the IRI using the Into trait.

pub fn clone_map<'a, U, F>(&'a self, factory: F) -> Iri<U> where
    U: TermData,
    F: FnMut(&'a str) -> U, 
[src]

Clone self while transforming the inner TermData with the given factory.

This is done in one step in contrast to calling clone().map(factory).

pub fn clone_into<'src, U>(&'src self) -> Iri<U> where
    U: TermData + From<&'src str>, 
[src]

Apply clone_map() using the Into trait.

pub fn len(&self) -> usize[src]

The length of this IRI.

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

👎 Deprecated:

An empty IRI is not a valid one

Checks if the IRI is empty

pub fn bytes(&self) -> impl '_ + Iterator<Item = u8>[src]

Iterate over the bytes representing this IRI.

pub fn chars(&self) -> impl '_ + Iterator<Item = char>[src]

Iterate over the characters representing this IRI.

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

Whether this IRI is is composed of a whole IRI (false) or a namespace and a suffix (true).

pub fn normalized(&self, policy: Normalization) -> Iri<MownStr<'_>>[src]

Return an IRI equivalent to this one, internally represented with all its data in ns, and an empty suffix.

Performances

The returned IRI will borrow data from this one as much as possible, but strings may be allocated in case a concatenation is required.

pub fn normalized_no_suffix(&self) -> Iri<MownStr<'_>>[src]

Return an IRI equivalent to this one, internally represented with all its data in ns, and an empty suffix.

Performances

If this IRI has an empty suffix, the returned IRI simply borrows its ns. Otherwise, a new string is allocated for the returned IRI.

pub fn normalized_suffixed_at_last_gen_delim(&self) -> Iri<MownStr<'_>>[src]

Return an IRI equivalent to this one, internally represented with ns extending to the last gen-delims characters (i.e. ":" / "/" / "?" / "#" / "[" / "]" / "@"). and suffix` containing the rest.

Performances

The returned IRI will borrow data from this one as much as possible, but strings may be allocated in case a concatenation is required.

pub fn match_ns<'s, U>(
    &'s self,
    ns: &Iri<U>
) -> Option<impl 's + Iterator<Item = char>> where
    U: TermData
[src]

Checks if the IRI matches a namespace.

If it does the remaining suffix is returned as iterator of chars. This prevents an additional allocation.

In case the ns and the IRI are the same, the function succeeds but returns an empty Iterator.

pub fn parse_components<'s>(&'s self, buffer: &'s mut String) -> IriParsed<'s>[src]

Parses the components of the IRI.

This is necessary to use the IRI as a base to resolve other IRIs.

Auxiliary buffer

The buffer parameter is only required in the situation where the internal representation of this Iri makes it unsuitable for building an IriParsed (typically because it is split in an ns and a suffix part). In those situations, the buffer will be used to store the full IRI, and will be borrowed by the returned IriParsed.

Otherwise, the buffer will not be used, the data will be borrowed directly from self.

Implementation detail

Currently, the buffer is used whenever the IRI is internally stored in two parts (ns and suffix), i.e. when it was created with new_suffixed.

Technically a suffixed IRI could parsed successfully when the suffix is separating the IRI at a component. However, detecting this requires more effort. Maybe this feature will be implemented (by you?) in a future release of sophia.

pub fn write_fmt<W>(&self, w: &mut W) -> Result where
    W: Write
[src]

Writes the IRI to the fmt::Write using the NTriples syntax.

This means the IRI is in angled brackets and no prefix is used.

pub fn write_io<W>(&self, w: &mut W) -> Result<()> where
    W: Write
[src]

Writes the IRI to the io::Write using the N3 syntax.

Trait Implementations

impl<TD: Clone + TermData> Clone for Iri<TD>[src]

impl<TD: Copy + TermData> Copy for Iri<TD>[src]

impl<TD: Debug + TermData> Debug for Iri<TD>[src]

impl<TD> Display for Iri<TD> where
    TD: TermData
[src]

impl<TD: Eq + TermData> Eq for Iri<TD>[src]

impl<'a> From<Iri<&'a str>> for SimpleIri<'a>[src]

impl<TD> From<Iri<TD>> for Term<TD> where
    TD: TermData
[src]

impl<TD> From<Namespace<TD>> for Iri<TD> where
    TD: TermData
[src]

impl<'a, TD> From<SimpleIri<'a>> for Iri<TD> where
    TD: TermData + From<&'a str>, 
[src]

impl<TD> Hash for Iri<TD> where
    TD: TermData
[src]

impl<TD: Ord + TermData> Ord for Iri<TD>[src]

impl<TD, TE: ?Sized> PartialEq<TE> for Iri<TD> where
    TD: TermData,
    TE: TTerm
[src]

impl<TD, TE: ?Sized> PartialOrd<TE> for Iri<TD> where
    TD: TermData,
    TE: TTerm
[src]

impl<'a, 'b, TD> Resolve<&'a Iri<TD>, Iri<MownStr<'a>>> for IriParsed<'b> where
    TD: TermData
[src]

fn resolve(&self, other: &'a Iri<TD>) -> Iri<MownStr<'a>>[src]

Resolve the given IRI.

Performance

May allocate an intermediate IRI if other is suffixed.

impl<'a, 'b> Resolve<Iri<&'a str>, Iri<MownStr<'a>>> for IriParsed<'b>[src]

fn resolve(&self, other: Iri<&'a str>) -> Iri<MownStr<'a>>[src]

Resolve the given IRI.

Performance

May allocate an intermediate IRI if other is suffixed.

impl<TD: TermData> StructuralEq for Iri<TD>[src]

impl<TD: TermData> TTerm for Iri<TD>[src]

impl<TD> TryCopyTerm for Iri<TD> where
    TD: TermData + for<'x> From<&'x str>, 
[src]

type Error = TermError

The error type produced when failing to copy a given term

impl<'a, T, U> TryFrom<&'a Term<U>> for Iri<T> where
    T: TermData + From<&'a str>,
    U: TermData
[src]

type Error = TermError

The type returned in the event of a conversion error.

impl<TD> TryFrom<Iri<TD>> for Namespace<TD> where
    TD: TermData
[src]

type Error = TermError

The type returned in the event of a conversion error.

fn try_from(iri: Iri<TD>) -> Result<Self, Self::Error>[src]

Requires that the given Iri has no suffix. This can be enforced with the clone_no_suffix() method.

impl<TD> TryFrom<Term<TD>> for Iri<TD> where
    TD: TermData
[src]

type Error = TermError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<TD> RefUnwindSafe for Iri<TD> where
    TD: RefUnwindSafe

impl<TD> Send for Iri<TD> where
    TD: Send

impl<TD> Sync for Iri<TD> where
    TD: Sync

impl<TD> Unpin for Iri<TD> where
    TD: Unpin

impl<TD> UnwindSafe for Iri<TD> where
    TD: UnwindSafe

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> ConvertibleTerm for T where
    T: TTerm + ?Sized
[src]

impl<T> CopiableTerm for T where
    T: TTerm + ?Sized
[src]

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

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

impl<U> TermMatcher for U where
    U: TTerm + ?Sized
[src]

type Term = U

Type of TTerm used internally by this matcher.

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.