pub struct BaseUrl { /* private fields */ }Expand description
The absolute URL an application is publicly reachable at, like
https://example.com.
Relative URLs work anywhere within the site, but rendered content that
leaves it (e.g. links and images in emails, feeds, or sitemaps) needs
the absolute form, resolved against this base. A base URL is an http or
https URL with a host and an optional path prefix (for applications
mounted under one, like https://example.com/app), and no query or
fragment. The string is parsed at construction, so every value of this
type holds a well-formed base.
Register one on the router builder with .base_url(...), read it back
with base_url or try_base_url, and resolve paths against it with
join:
use topcoat::context::BaseUrl;
let base = BaseUrl::new("https://example.com")?;
assert_eq!(
base.join("/assets/logo.png"),
"https://example.com/assets/logo.png"
);Implementations§
Source§impl BaseUrl
impl BaseUrl
Sourcepub fn new(url: impl AsRef<str>) -> Result<BaseUrl, BaseUrlError>
pub fn new(url: impl AsRef<str>) -> Result<BaseUrl, BaseUrlError>
Parses a base URL.
The scheme and any trailing slash are normalized, so
https://example.com/app/ and https://example.com/app are the
same base.
§Errors
Returns BaseUrlError if the string is not an absolute http or
https URL, or carries a query string or fragment.
Sourcepub fn join(&self, path: &str) -> String
pub fn join(&self, path: &str) -> String
Resolves a root-relative path into an absolute URL.
The path is taken as relative to the application root whether or not
it starts with a slash: base.join("/assets/logo.png") and
base.join("assets/logo.png") produce the same URL. A query string
on the path is carried through.
Trait Implementations§
impl Eq for BaseUrl
impl StructuralPartialEq for BaseUrl
Auto Trait Implementations§
impl Freeze for BaseUrl
impl RefUnwindSafe for BaseUrl
impl Send for BaseUrl
impl Sync for BaseUrl
impl Unpin for BaseUrl
impl UnsafeUnpin for BaseUrl
impl UnwindSafe for BaseUrl
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
impl<T> CloneAny for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.