Function iri_string::resolve::try_resolve_whatwg
source · [−]pub fn try_resolve_whatwg<S: Spec>(
reference: impl AsRef<RiReferenceStr<S>>,
base: impl AsRef<RiAbsoluteStr<S>>
) -> Result<RiString<S>, TaskError<Infallible>>Expand description
Resolves the IRI reference.
It is recommended to use methods such as RiReferenceStr::try_resolve_whatwg_against()
and RiRelativeStr::try_resolve_whatwg_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.
Examples
use iri_string::resolve::{try_resolve_whatwg, FixedBaseResolver};
use iri_string::task::ProcessAndWrite;
use iri_string::types::{IriAbsoluteStr, IriReferenceStr};
let base = IriAbsoluteStr::new("scheme:/path")?;
let reference = IriReferenceStr::new("..//not-a-host")?;
// Resolve `reference` against `base`.
let resolved = try_resolve_whatwg(reference, base)?;
// Note that the result is not `scheme://not-a-host`.
assert_eq!(resolved, "scheme:/.//not-a-host");