Crate base_url[−][src]
base_url is a thin wrapper around rust-url, which itself implements the URL Standard. The goal of base_url is to remove redundant error checks related to the base-suitability of a given URL.
Acquiring a BaseUrl object
A BaseUrl object may be acquired by either converting a Url or &str using the TryInto/TryFrom traits. If a &str cannot be parsed into a Url object a BaseUrlError::ParseError will be returned which wraps the underlying ParseError type implemented by rust-url.
use base_url::{ BaseUrl, BaseUrlError, Url, ParseError }; assert!( BaseUrl::try_from( "http://[:::1]" ) == Err( BaseUrlError::ParseError( ParseError::InvalidIpv6Address ) ) );
That's a bit unwieldly, so it's suggested that you prefer first parsing the &str into a Url and converting that object into a BaseUrl, allowing you to deal with errors related to parsing separately from errors related to base suitability.
use base_url::{ BaseUrl, BaseUrlError, Url }; let url:Url = Url::parse( "data:text/plain,Hello?World#" )?; assert!( BaseUrl::try_from( url ) == BaseUrlError::CannotBeBase );
Once we have a BaseUrl we can do (almost) anything we could with a normal Url and with fewer functions admitting potential failures
Re-exports
pub extern crate url; |
Structs
BaseUrl |
Any Url which has a host and so can be supplied as a base url |
Url |
A parsed URL record. |
Enums
BaseUrlError | |
Host |
The host name of an URL. |
ParseError |
Errors that can occur during parsing. |
Type Definitions
OriginTuple |
A representation of the origin of a BaseUrl |