Function iri_string::resolve::resolve
source · [−]pub fn resolve<S: Spec>(
reference: impl AsRef<RiReferenceStr<S>>,
base: impl AsRef<RiAbsoluteStr<S>>
) -> Result<RiString<S>, TaskError<Error>>
Expand description
Resolves the IRI reference.
It is recommended to use methods such as RiReferenceStr::resolve_against()
and
RiRelativeStr::resolve_against()
, rather than this freestanding function.
If you are going to resolve multiple references against the common base,
consider using FixedBaseResolver
.
Enabled by alloc
or std
feature.
Failures
This fails if
- memory allocation failed, or
- the IRI referernce is unresolvable against the base.
To see examples of unresolvable IRIs, visit the documentation
for normalize::Error
.
Examples
use iri_string::resolve::{resolve, FixedBaseResolver};
use iri_string::task::ProcessAndWrite;
use iri_string::types::{IriAbsoluteStr, IriReferenceStr};
let base = IriAbsoluteStr::new("http://example.com/base/")?;
let reference = IriReferenceStr::new("../there")?;
// Resolve `reference` against `base`.
let resolved = resolve(reference, base)?;
assert_eq!(resolved, "http://example.com/there");
// These two produces the same result with the same type.
assert_eq!(
FixedBaseResolver::new(base).resolve(reference)?,
"http://example.com/there"
);
assert_eq!(
FixedBaseResolver::new(base).create_task(reference).allocate_and_write()?,
"http://example.com/there"
);