pub struct Resolver<R> { /* private fields */ }Available on crate feature
alloc only.Expand description
A configurable URI/IRI reference resolver against a fixed base.
§Examples
use fluent_uri::{resolve::Resolver, Uri, UriRef};
let base = Uri::parse("http://example.com/foo/bar")?;
let resolver = Resolver::with_base(base);
assert_eq!(resolver.resolve(&UriRef::parse("baz")?).unwrap(), "http://example.com/foo/baz");
assert_eq!(resolver.resolve(&UriRef::parse("../baz")?).unwrap(), "http://example.com/baz");
assert_eq!(resolver.resolve(&UriRef::parse("?baz")?).unwrap(), "http://example.com/foo/bar?baz");Implementations§
Source§impl<R: Ri> Resolver<R>
impl<R: Ri> Resolver<R>
Sourcepub fn with_base(base: R) -> Self
pub fn with_base(base: R) -> Self
Creates a new Resolver with the given base and default configuration.
Sourcepub fn allow_path_underflow(self, value: bool) -> Self
pub fn allow_path_underflow(self, value: bool) -> Self
Sets whether to allow underflow in path resolution.
This defaults to true. A value of false is a deviation from the
reference resolution algorithm defined in
Section 5 of RFC 3986.
§Examples
use fluent_uri::{resolve::{Resolver, ResolveError}, Uri, UriRef};
let base = Uri::parse("http://example.com/foo/bar")?;
let resolver = Resolver::with_base(base).allow_path_underflow(false);
assert_eq!(resolver.resolve(&UriRef::parse("../../baz")?).unwrap_err(), ResolveError::PathUnderflow);
assert_eq!(resolver.resolve(&UriRef::parse("../../../baz")?).unwrap_err(), ResolveError::PathUnderflow);
assert_eq!(resolver.resolve(&UriRef::parse("/../baz")?).unwrap_err(), ResolveError::PathUnderflow);Sourcepub fn resolve<T: Bos<str>>(
&self,
reference: &R::Ref<T>,
) -> Result<R::WithVal<String>, ResolveError>
pub fn resolve<T: Bos<str>>( &self, reference: &R::Ref<T>, ) -> Result<R::WithVal<String>, ResolveError>
Resolves the given reference against the configured base.
See resolve_against for the exact behavior of this method.
§Errors
Returns Err on the same conditions as resolve_against or if an underflow
occurred in path resolution when allow_path_underflow is set to false.
Trait Implementations§
impl<R: Copy> Copy for Resolver<R>
Auto Trait Implementations§
impl<R> Freeze for Resolver<R>where
R: Freeze,
impl<R> RefUnwindSafe for Resolver<R>where
R: RefUnwindSafe,
impl<R> Send for Resolver<R>where
R: Send,
impl<R> Sync for Resolver<R>where
R: Sync,
impl<R> Unpin for Resolver<R>where
R: Unpin,
impl<R> UnwindSafe for Resolver<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more