BetterUrl

Struct BetterUrl 

Source
pub struct BetterUrl { /* private fields */ }
Expand description

A wrapper around a Url with extra metadata.

Currently the only included metadata is a HostDetails, which currently only caches PSL information for more efficient reg domain, domain suffix, etc..

Implementations§

Source§

impl BetterUrl

Source

pub fn set_path(&mut self, path: &str)

Source

pub fn path_has_segments(&self) -> bool

Returns true if the path has segments.

Source

pub fn set_path_segments<'a, I>( &mut self, iter: I, ) -> Result<(), SetPathSegmentsError>
where I: IntoIterator<Item = &'a str>,

Set Url::path_segments.

§Errors

If the URL doesn’t have path segments, returns the error SetPathSegmentsError::UrlDoesNotHavePathSegments.

If iter has a length of zero, returns the error SetPathSegmentsError::CannotHaveZeroPathSegments.

If a segment contains a /, returns the error SetPathSegmentsError::PathSegmentCannotContainSlash.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com").unwrap();

url.set_path_segments([]).unwrap_err();

url.set_path_segments(["a"]).unwrap();
assert_eq!(url.path(), "/a");

url.set_path_segments(["a", "b"]).unwrap();
assert_eq!(url.path(), "/a/b");

url.set_path_segments(["a/b/c"]).unwrap_err();
assert_eq!(url.path(), "/a/b");
Source

pub fn set_raw_path_segments<'a, I>( &mut self, iter: I, ) -> Result<(), SetPathSegmentsError>
where I: IntoIterator<Item = &'a str>,

Set Url::path_segments without checking if a segment contains a /.

Useful for optimizations.

§Errors

If the URL doesn’t have path segments, returns the error SetPathSegmentsError::UrlDoesNotHavePathSegments.

If iter has a length of zero, returns the error SetPathSegmentsError::CannotHaveZeroPathSegments.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com").unwrap();

url.set_raw_path_segments([]).unwrap_err();

url.set_raw_path_segments(["a"]).unwrap();
assert_eq!(url.path(), "/a");

url.set_raw_path_segments(["a", "b"]).unwrap();
assert_eq!(url.path(), "/a/b");

url.set_raw_path_segments(["a/b/c"]).unwrap();
assert_eq!(url.path(), "/a/b/c");
Source

pub fn set_path_segments_str( &mut self, to: &str, ) -> Result<(), SetPathSegmentsStrError>

Set Url::path_segments.

§Errors

If the URL doesn’t have path segments, returns the error SetPathSegmentsStrError::UrlDoesNotHavePathSegments.

Source

pub fn path_segment(&self, index: isize) -> Option<Option<&str>>

Gets the specified path segment.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com/a/b/c").unwrap();

assert_eq!(url.path_segment(-4), Some(None            ));
assert_eq!(url.path_segment(-3), Some(Some("a".into())));
assert_eq!(url.path_segment(-2), Some(Some("b".into())));
assert_eq!(url.path_segment(-1), Some(Some("c".into())));
assert_eq!(url.path_segment( 0), Some(Some("a".into())));
assert_eq!(url.path_segment( 1), Some(Some("b".into())));
assert_eq!(url.path_segment( 2), Some(Some("c".into())));
assert_eq!(url.path_segment( 3), Some(None            ));
Source

pub fn path_segments_mut(&mut self) -> Option<PathSegmentsMut<'_>>

Gets an object that can mutate the segments of Self’s path.

§Examples
use better_url::*;
let mut url = BetterUrl::parse("https://example.com/a/b/c/").unwrap();

url.path_segments_mut().unwrap().pop(); assert_eq!(url.path(), "/a/b/c");
url.path_segments_mut().unwrap().pop(); assert_eq!(url.path(), "/a/b");
url.path_segments_mut().unwrap().pop(); assert_eq!(url.path(), "/a");
url.path_segments_mut().unwrap().pop(); assert_eq!(url.path(), "/");
url.path_segments_mut().unwrap().pop(); assert_eq!(url.path(), "/");
Source

pub fn path_segments_str(&self) -> Option<&str>

Url::path with the leading / removed.

When split on /, gives identical values to Url::path_segments.

Source

pub fn set_path_segment( &mut self, index: isize, value: Option<&str>, ) -> Result<(), SetPathSegmentError>

Sets the specified path segment.

§Errors

If a segment contains a /, returns the error SetPathSegmentsError::PathSegmentCannotContainSlash.

If the call to Self::set_raw_path_segment returns an error, that error is returned.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com/aa/bb/cc").unwrap();

url.set_path_segment(-4, Some("-4")).unwrap_err(); assert_eq!(url.path(), "/aa/bb/cc");
url.set_path_segment(-3, Some("-3")).unwrap    (); assert_eq!(url.path(), "/-3/bb/cc");
url.set_path_segment(-2, Some("-2")).unwrap    (); assert_eq!(url.path(), "/-3/-2/cc");
url.set_path_segment(-1, Some("-1")).unwrap    (); assert_eq!(url.path(), "/-3/-2/-1");
url.set_path_segment( 0, Some("00")).unwrap    (); assert_eq!(url.path(), "/00/-2/-1");
url.set_path_segment( 1, Some("+1")).unwrap    (); assert_eq!(url.path(), "/00/+1/-1");
url.set_path_segment( 2, Some("+2")).unwrap    (); assert_eq!(url.path(), "/00/+1/+2");
url.set_path_segment( 3, Some("+3")).unwrap_err(); assert_eq!(url.path(), "/00/+1/+2");

url.set_path_segment( 0, None).unwrap(); assert_eq!(url.path(), "/+1/+2");
url.set_path_segment(-1, None).unwrap(); assert_eq!(url.path(), "/+1");
Source

pub fn set_raw_path_segment( &mut self, index: isize, value: Option<&str>, ) -> Result<(), SetPathSegmentError>

Sets the specified path segment without checking if the segment contains a /.

Useful for optimizations.

§Errors

If the call to Self::path_segments_str returns None, returns the error SetPathSegmentError::UrlDoesNotHavePathSegments.

If the specified path segment isn’t found, returns the error SetPathSegmentError::SegmentNotFound.

Source

pub fn insert_path_segment( &mut self, index: isize, value: &str, ) -> Result<(), InsertPathSegmentError>

Inserts a path segment at the specified path segment.

If the specified segment is one after the last, inserts a new segment at the end.

§Errors

If the call to Self::path_segments_str returns None, returns the error InsertPathSegmentError::UrlDoesNotHavePathSegments.

If the specified path segment isn’t found, returns the error InsertPathSegmentError::SegmentNotFound.

If a segment contains a /, returns the error SetPathSegmentsError::PathSegmentCannotContainSlash.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com/").unwrap();

url.insert_path_segment(0, "abc").unwrap();
assert_eq!(url.path(), "/abc/");

url.insert_path_segment(0, "def").unwrap();
assert_eq!(url.path(), "/def/abc/");

url.insert_path_segment(3, "ghi").unwrap();
assert_eq!(url.path(), "/def/abc//ghi");

url.insert_path_segment(6, "err").unwrap_err();
assert_eq!(url.path(), "/def/abc//ghi");

url.insert_path_segment(0, "a/b").unwrap_err();
assert_eq!(url.path(), "/def/abc//ghi");
Source

pub fn insert_raw_path_segment( &mut self, index: isize, value: &str, ) -> Result<(), InsertPathSegmentError>

Inserts a path segment at the specified path segment without checking if a segment contains a /.

If the specified segment is one after the last, inserts a new segment at the end.

§Errors

If the call to Self::path_segments_str returns None, returns the error InsertPathSegmentError::UrlDoesNotHavePathSegments.

If the specified path segment isn’t found, returns the error InsertPathSegmentError::SegmentNotFound.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com/").unwrap();

url.insert_raw_path_segment(0, "abc").unwrap();
assert_eq!(url.path(), "/abc/");

url.insert_raw_path_segment(0, "def").unwrap();
assert_eq!(url.path(), "/def/abc/");

url.insert_raw_path_segment(3, "ghi").unwrap();
assert_eq!(url.path(), "/def/abc//ghi");

url.insert_raw_path_segment(6, "err").unwrap_err();
assert_eq!(url.path(), "/def/abc//ghi");

url.insert_raw_path_segment(0, "a/b").unwrap();
assert_eq!(url.path(), "/a/b/def/abc//ghi");
Source

pub fn first_n_path_segments(&self, n: usize) -> Option<Option<&str>>

Get the first n path segments.

Source

pub fn path_segments_after_first_n(&self, n: usize) -> Option<Option<&str>>

Gets the path segments except for the first n.

Source

pub fn last_n_path_segments(&self, n: usize) -> Option<Option<&str>>

Get the last n path segments.

Source

pub fn path_segments_before_last_n(&self, n: usize) -> Option<Option<&str>>

Gets the path segments except for the last n.

Source

pub fn set_first_n_path_segments( &mut self, n: usize, to: Option<&str>, ) -> Result<(), SetFirstNPathSegmentsError>

Sets the first n path segments.

Does not require to to have n segments.

§Errors

If the URL doesn’t have path segments, returns the error SetFirstNPathSegmentsError::UrlDoesNotHavePathSegments.

If there aren’t enough path segments, returns the error SetFirstNPathSegmentsError::NotEnoughPathSegments.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com/0/1/2/3/4/5").unwrap();

url.set_first_n_path_segments(0, Some("a")).unwrap();
assert_eq!(url.path(), "/0/1/2/3/4/5");
url.set_first_n_path_segments(0, None).unwrap();
assert_eq!(url.path(), "/0/1/2/3/4/5");

url.set_first_n_path_segments(1, Some("a")).unwrap();
assert_eq!(url.path(), "/a/1/2/3/4/5");
url.set_first_n_path_segments(1, None).unwrap();
assert_eq!(url.path(), "/1/2/3/4/5");

url.set_first_n_path_segments(2, Some("a")).unwrap();
assert_eq!(url.path(), "/a/3/4/5");
url.set_first_n_path_segments(2, None).unwrap();
assert_eq!(url.path(), "/4/5");

url.set_first_n_path_segments(3, Some("a")).unwrap_err();
assert_eq!(url.path(), "/4/5");
url.set_first_n_path_segments(3, None).unwrap_err();
assert_eq!(url.path(), "/4/5");
Source

pub fn set_path_segments_after_first_n( &mut self, n: usize, to: Option<&str>, ) -> Result<(), SetPathSegmentsAfterFirstNError>

Sets the path segments except for the first n.

Does not require to to have n segments.

§Errors

If the URL doesn’t have path segments, returns the error SetFirstNPathSegmentsError::UrlDoesNotHavePathSegments.

If there aren’t enough path segments, returns the error SetFirstNPathSegmentsError::NotEnoughPathSegments.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com/0/1/2/3/4/5").unwrap();

url.set_path_segments_after_first_n(3, Some("a")).unwrap();
assert_eq!(url.path(), "/0/1/2/a");
url.set_path_segments_after_first_n(3, None).unwrap();
assert_eq!(url.path(), "/0/1/2");

url.set_path_segments_after_first_n(2, Some("a")).unwrap();
assert_eq!(url.path(), "/0/1/a");
url.set_path_segments_after_first_n(2, None).unwrap();
assert_eq!(url.path(), "/0/1");

url.set_path_segments_after_first_n(1, Some("a")).unwrap();
assert_eq!(url.path(), "/0/a");
url.set_path_segments_after_first_n(1, None).unwrap();
assert_eq!(url.path(), "/0");

url.set_path_segments_after_first_n(0, Some("a")).unwrap();
assert_eq!(url.path(), "/a");
url.set_path_segments_after_first_n(0, None).unwrap_err();
assert_eq!(url.path(), "/a");
Source

pub fn set_last_n_path_segments( &mut self, n: usize, to: Option<&str>, ) -> Result<(), SetLastNPathSegmentsError>

Sets the last n path segments.

Does not require to to have n segments.

§Errors

If the URL doesn’t have path segments, returns the error SetLastNPathSegmentsError::UrlDoesNotHavePathSegments.

If there aren’t enough path segments, returns the error SetLastNPathSegmentsError::NotEnoughPathSegments.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com/0/1/2/3/4/5").unwrap();

url.set_last_n_path_segments(0, Some("a")).unwrap();
assert_eq!(url.path(), "/0/1/2/3/4/5");
url.set_last_n_path_segments(0, None).unwrap();
assert_eq!(url.path(), "/0/1/2/3/4/5");

url.set_last_n_path_segments(1, Some("a")).unwrap();
assert_eq!(url.path(), "/0/1/2/3/4/a");
url.set_last_n_path_segments(1, None).unwrap();
assert_eq!(url.path(), "/0/1/2/3/4");

url.set_last_n_path_segments(2, Some("a")).unwrap();
assert_eq!(url.path(), "/0/1/2/a");
url.set_last_n_path_segments(2, None).unwrap();
assert_eq!(url.path(), "/0/1");

url.set_last_n_path_segments(3, Some("a")).unwrap_err();
assert_eq!(url.path(), "/0/1");
url.set_last_n_path_segments(3, None).unwrap_err();
assert_eq!(url.path(), "/0/1");
Source

pub fn set_path_segments_before_last_n( &mut self, n: usize, to: Option<&str>, ) -> Result<(), SetPathSegmentsBeforeLastNError>

Sets the path segments except for the last n.

Does not require to to have n segments.

§Errors

If the URL doesn’t have path segments, returns the error SetLastNPathSegmentsError::UrlDoesNotHavePathSegments.

If there aren’t enough path segments, returns the error SetLastNPathSegmentsError::NotEnoughPathSegments.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com/0/1/2/3/4/5").unwrap();

url.set_path_segments_before_last_n(3, Some("a")).unwrap();
assert_eq!(url.path(), "/a/3/4/5");
url.set_path_segments_before_last_n(3, None).unwrap();
assert_eq!(url.path(), "/3/4/5");

url.set_path_segments_before_last_n(2, Some("a")).unwrap();
assert_eq!(url.path(), "/a/4/5");
url.set_path_segments_before_last_n(2, None).unwrap();
assert_eq!(url.path(), "/4/5");

url.set_path_segments_before_last_n(1, Some("a")).unwrap();
assert_eq!(url.path(), "/a/5");
url.set_path_segments_before_last_n(1, None).unwrap();
assert_eq!(url.path(), "/5");

url.set_path_segments_before_last_n(0, Some("a")).unwrap();
assert_eq!(url.path(), "/a");
url.set_path_segments_before_last_n(0, None).unwrap_err();
assert_eq!(url.path(), "/a");
Source

pub fn remove_first_n_path_segments( &mut self, n: usize, ) -> Result<(), RemoveFirstNPathSegmentsError>

Remove the first n path segments.

The number of path segments after this succeeds is equal to the number of path segments before this is applied minus n.

Because a path can’t have zero segments, trying to remove all segments counts as not having enough segments. If this is a serious ergonomics issue for you, I’ll prioritize making a workaround.

§Errors

If the URL doesn’t have path segments, returns the error RemoveFirstNPathSegmentsError::UrlDoesNotHavePathSegments.

If there aren’t enough segments, returns the error RemoveFirstNPathSegmentsError::NotEnoughPathSegments.

Source

pub fn keep_first_n_path_segments( &mut self, n: usize, ) -> Result<(), KeepFirstNPathSegmentsError>

Keep the first n path segments.

The number of path segments after this succeeds is equal to n.

Because a path can’t have zero segments, trying to keep zero segments always errors. This is easy to just not do.

§Errors

If the URL doesn’t have path segments, returns the error KeepFirstNPathSegmentsError::UrlDoesNotHavePathSegments.

If there aren’t enough segments, returns the error KeepFirstNPathSegmentsError::NotEnoughPathSegments.

Source

pub fn remove_last_n_path_segments( &mut self, n: usize, ) -> Result<(), RemoveLastNPathSegmentsError>

Remove the last n path segments.

The number of path segments after this succeeds is equal to the number of path segments before this is applied minus n.

Because a path can’t have zero segments, trying to remove all segments counts as not having enough segments. If this is a serious ergonomics issue for you, I’ll prioritize making a workaround.

§Errors

If the URL doesn’t have path segments, returns the error RemoveLastNPathSegmentsError::UrlDoesNotHavePathSegments.

If there aren’t enough segments, returns the error RemoveLastNPathSegmentsError::NotEnoughPathSegments.

Source

pub fn keep_last_n_path_segments( &mut self, n: usize, ) -> Result<(), KeepLastNPathSegmentsError>

Keep the last n path segments.

The number of path segments after this succeeds is equal to n.

Because a path can’t have zero segments, trying to keep zero segments always errors. This is easy to just not do.

§Errors

If the URL doesn’t have path segments, returns the error KeepLastNPathSegmentsError::UrlDoesNotHavePathSegments.

If there aren’t enough segments, returns the error KeepLastNPathSegmentsError::NotEnoughPathSegments.

Source§

impl BetterUrl

Source

pub fn domain_segment(&self, index: isize) -> Option<&str>

§Examples
use better_url::*;

let url = BetterUrl::parse("https://abc.def.example.co.uk").unwrap();

assert_eq!(url.domain_segment(-6), None                  );
assert_eq!(url.domain_segment(-5), Some("abc"    .into()));
assert_eq!(url.domain_segment(-4), Some("def"    .into()));
assert_eq!(url.domain_segment(-3), Some("example".into()));
assert_eq!(url.domain_segment(-2), Some("co"     .into()));
assert_eq!(url.domain_segment(-1), Some("uk"     .into()));

assert_eq!(url.domain_segment( 0), Some("abc"    .into()));
assert_eq!(url.domain_segment( 1), Some("def"    .into()));
assert_eq!(url.domain_segment( 2), Some("example".into()));
assert_eq!(url.domain_segment( 3), Some("co"     .into()));
assert_eq!(url.domain_segment( 4), Some("uk"     .into()));
assert_eq!(url.domain_segment( 5), None                  );
Source

pub fn set_domain_segment( &mut self, index: isize, value: Option<&str>, ) -> Result<(), SetDomainSegmentError>

Sets the specified domain segment.

§Errors

If the URL doesn’t have a domain, returns the error SetDomainSegmentError::UrlDoesNotHaveDomain.

If the segment isn’t found, returns the error SetDomainSegmentError::SegmentNotFound.

If the call to Self::set_domain returns an error, that error is returned.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://abc.def.example.co.uk").unwrap();

url.set_domain_segment(-6, Some("n6")).unwrap_err(); assert_eq!(url.host_str(), Some("abc.def.example.co.uk"));
url.set_domain_segment(-5, Some("n5")).unwrap    (); assert_eq!(url.host_str(), Some("n5.def.example.co.uk" ));
url.set_domain_segment(-4, Some("n4")).unwrap    (); assert_eq!(url.host_str(), Some("n5.n4.example.co.uk"  ));
url.set_domain_segment(-3, Some("n3")).unwrap    (); assert_eq!(url.host_str(), Some("n5.n4.n3.co.uk"       ));
url.set_domain_segment(-2, Some("n2")).unwrap    (); assert_eq!(url.host_str(), Some("n5.n4.n3.n2.uk"       ));
url.set_domain_segment(-1, Some("n1")).unwrap    (); assert_eq!(url.host_str(), Some("n5.n4.n3.n2.n1"       ));

url.set_domain_segment( 0, Some("p0")).unwrap    (); assert_eq!(url.host_str(), Some("p0.n4.n3.n2.n1"       ));
url.set_domain_segment( 1, Some("p1")).unwrap    (); assert_eq!(url.host_str(), Some("p0.p1.n3.n2.n1"       ));
url.set_domain_segment( 2, Some("p2")).unwrap    (); assert_eq!(url.host_str(), Some("p0.p1.p2.n2.n1"       ));
url.set_domain_segment( 3, Some("p3")).unwrap    (); assert_eq!(url.host_str(), Some("p0.p1.p2.p3.n1"       ));
url.set_domain_segment( 4, Some("p4")).unwrap    (); assert_eq!(url.host_str(), Some("p0.p1.p2.p3.p4"       ));
url.set_domain_segment( 5, Some("p5")).unwrap_err(); assert_eq!(url.host_str(), Some("p0.p1.p2.p3.p4"       ));



url.set_domain_segment( 0, None).unwrap(); assert_eq!(url.host_str(), Some("p1.p2.p3.p4"));
url.set_domain_segment(-1, None).unwrap(); assert_eq!(url.host_str(), Some("p1.p2.p3"));
Source

pub fn insert_domain_segment( &mut self, index: isize, value: &str, ) -> Result<(), InsertDomainSegmentError>

Inserts a new domain segment at the specified index.

§Errors

If the URL doesn’t have a domain, returns the error InsertDomainSegmentError::UrlDoesNotHaveDomain.

If the segment isn’t found, returns the error InsertDomainSegmentError::SegmentNotFound.

If the call to Self::set_domain returns an error, that error is returned.

Source§

impl BetterUrl

Source

pub fn subdomain_segment(&self, index: isize) -> Option<&str>

§Examples
use better_url::*;

let url = BetterUrl::parse("https://abc.def.example.co.uk").unwrap();

assert_eq!(url.subdomain_segment(-3), None              );
assert_eq!(url.subdomain_segment(-2), Some("abc".into()));
assert_eq!(url.subdomain_segment(-1), Some("def".into()));

assert_eq!(url.subdomain_segment( 0), Some("abc".into()));
assert_eq!(url.subdomain_segment( 1), Some("def".into()));
assert_eq!(url.subdomain_segment( 2), None              );
Source

pub fn set_subdomain_segment( &mut self, index: isize, value: Option<&str>, ) -> Result<(), SetSubdomainSegmentError>

Sets the specified subdomain segment.

§Errors

If the URL doesn’t have a domain, returns the error SetSubdomainSegmentError::UrlDoesNotHaveSubdomain.

If the segment isn’t found, returns the error SetSubdomainSegmentError::SegmentNotFound.

If the call to Self::set_subdomain returns an error, that error is returned.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://abc.def.example.co.uk").unwrap();

url.set_subdomain_segment(-3, Some("n3")).unwrap_err(); assert_eq!(url.host_str(), Some("abc.def.example.co.uk"));
url.set_subdomain_segment(-2, Some("n2")).unwrap    (); assert_eq!(url.host_str(), Some("n2.def.example.co.uk"));
url.set_subdomain_segment(-1, Some("n1")).unwrap    (); assert_eq!(url.host_str(), Some("n2.n1.example.co.uk"));

url.set_subdomain_segment( 0, Some("p0")).unwrap    (); assert_eq!(url.host_str(), Some("p0.n1.example.co.uk"));
url.set_subdomain_segment( 1, Some("p1")).unwrap    (); assert_eq!(url.host_str(), Some("p0.p1.example.co.uk"));
url.set_subdomain_segment( 2, Some("p2")).unwrap_err(); assert_eq!(url.host_str(), Some("p0.p1.example.co.uk"));



url.set_subdomain_segment( 0, None).unwrap(); assert_eq!(url.host_str(), Some("p1.example.co.uk"));
url.set_subdomain_segment(-1, None).unwrap(); assert_eq!(url.host_str(), Some("example.co.uk"));
Source

pub fn insert_subdomain_segment( &mut self, index: isize, value: &str, ) -> Result<(), InsertSubdomainSegmentError>

Inserts a new subdomain segment at the specified index.

§Errors

If the URL doesn’t have a domain, returns the error InsertSubdomainSegmentError::UrlDoesNotHaveSubdomain.

If the segment isn’t found, returns the error InsertSubdomainSegmentError::SegmentNotFound.

If the call to Self::set_subdomain returns an error, that error is returned.

Source§

impl BetterUrl

Source

pub fn domain_suffix_segment(&self, index: isize) -> Option<&str>

§Examples
use better_url::*;

let url = BetterUrl::parse("https://abc.def.example.co.uk").unwrap();

assert_eq!(url.domain_suffix_segment(-3), None             );
assert_eq!(url.domain_suffix_segment(-2), Some("co".into()));
assert_eq!(url.domain_suffix_segment(-1), Some("uk".into()));

assert_eq!(url.domain_suffix_segment( 0), Some("co".into()));
assert_eq!(url.domain_suffix_segment( 1), Some("uk".into()));
assert_eq!(url.domain_suffix_segment( 2), None             );
Source

pub fn set_domain_suffix_segment( &mut self, index: isize, value: Option<&str>, ) -> Result<(), SetDomainSuffixSegmentError>

Sets the specified domain suffix segment.

§Errors

If the URL doesn’t have a domain, returns the error SetDomainSuffixSegmentError::UrlDoesNotHaveDomainSuffix.

If the segment isn’t found, returns the error SetDomainSuffixSegmentError::SegmentNotFound.

If the call to Self::set_domain_suffix returns an error, that error is returned.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://abc.def.example.co.uk").unwrap();

url.set_domain_suffix_segment(-3, Some("n3")).unwrap_err(); assert_eq!(url.host_str(), Some("abc.def.example.co.uk"));
url.set_domain_suffix_segment(-2, Some("n2")).unwrap    (); assert_eq!(url.host_str(), Some("abc.def.example.n2.uk"));
url.set_domain_suffix_segment(-1, Some("n1")).unwrap    (); assert_eq!(url.host_str(), Some("abc.def.example.n2.n1"));

// Setting a domain suffix segment may alter the amount of domain segments the suffix has, leading to weird results.
url.set_domain_suffix_segment( 0, Some("p0")).unwrap    (); assert_eq!(url.host_str(), Some("abc.def.example.n2.p0"));
url.set_domain_suffix_segment( 1, Some("p1")).unwrap_err(); assert_eq!(url.host_str(), Some("abc.def.example.n2.p0"));



url.set_domain_suffix_segment( 0, None).unwrap(); assert_eq!(url.host_str(), Some("abc.def.example.n2"));
url.set_domain_suffix_segment(-1, None).unwrap(); assert_eq!(url.host_str(), Some("abc.def.example"));
Source

pub fn insert_domain_suffix_segment( &mut self, index: isize, value: &str, ) -> Result<(), InsertDomainSuffixSegmentError>

Inserts a new domain suffix segment at the specified index.

§Errors

If the URL doesn’t have a domain, returns the error InsertDomainSuffixSegmentError::UrlDoesNotHaveDomainSuffix.

If the segment isn’t found, returns the error InsertDomainSuffixSegmentError::SegmentNotFound.

If the call to Self::set_domain_suffix returns an error, that error is returned.

Source§

impl BetterUrl

Source

pub fn domain(&self) -> Option<&str>

The domain, not including any fully qualified domain name period.

Specifically, if Self::host_details is HostDetails::Domain, return the substring of Url::host_str specified by DomainDetails::domain_bounds.

§Examples
use better_url::*;
assert_eq!(BetterUrl::parse("https://example.com"       ).unwrap().domain(), Some("example.com"      ));
assert_eq!(BetterUrl::parse("https://example.co.uk"     ).unwrap().domain(), Some("example.co.uk"    ));
assert_eq!(BetterUrl::parse("https://www.example.com"   ).unwrap().domain(), Some("www.example.com"  ));
assert_eq!(BetterUrl::parse("https://www.example.co.uk" ).unwrap().domain(), Some("www.example.co.uk"));
assert_eq!(BetterUrl::parse("https://www.example.com."  ).unwrap().domain(), Some("www.example.com"  ));
assert_eq!(BetterUrl::parse("https://www.example.co.uk.").unwrap().domain(), Some("www.example.co.uk"));
Source

pub fn subdomain(&self) -> Option<&str>

The subdomain.

Specifically, if Self::host_details is HostDetails::Domain, return the substring of Url::host_str specified by DomainDetails::subdomain_bounds.

§Examples
use better_url::*;
assert_eq!(BetterUrl::parse("https://example.com"       ).unwrap().subdomain(), None);
assert_eq!(BetterUrl::parse("https://example.co.uk"     ).unwrap().subdomain(), None);
assert_eq!(BetterUrl::parse("https://www.example.com"   ).unwrap().subdomain(), Some("www"));
assert_eq!(BetterUrl::parse("https://www.example.co.uk" ).unwrap().subdomain(), Some("www"));
assert_eq!(BetterUrl::parse("https://www.example.com."  ).unwrap().subdomain(), Some("www"));
assert_eq!(BetterUrl::parse("https://www.example.co.uk.").unwrap().subdomain(), Some("www"));
Source

pub fn not_domain_suffix(&self) -> Option<&str>

The “not domain suffix”, being Self::subdomain and Self::domain_middle.

Specifically, if Self::host_details is HostDetails::Domain, return the substring of Url::host_str specified by DomainDetails::not_domain_suffix_bounds.

§Examples
use better_url::*;
assert_eq!(BetterUrl::parse("https://example.com"       ).unwrap().not_domain_suffix(), Some("example"));
assert_eq!(BetterUrl::parse("https://example.co.uk"     ).unwrap().not_domain_suffix(), Some("example"));
assert_eq!(BetterUrl::parse("https://www.example.com"   ).unwrap().not_domain_suffix(), Some("www.example"));
assert_eq!(BetterUrl::parse("https://www.example.co.uk" ).unwrap().not_domain_suffix(), Some("www.example"));
assert_eq!(BetterUrl::parse("https://www.example.com."  ).unwrap().not_domain_suffix(), Some("www.example"));
assert_eq!(BetterUrl::parse("https://www.example.co.uk.").unwrap().not_domain_suffix(), Some("www.example"));
Source

pub fn domain_middle(&self) -> Option<&str>

The domain middle.

Specifically, if Self::host_details is HostDetails::Domain, return the substring of Url::host_str specified by DomainDetails::domain_middle_bounds.

§Examples
use better_url::*;
assert_eq!(BetterUrl::parse("https://example.com"       ).unwrap().domain_middle(), Some("example"));
assert_eq!(BetterUrl::parse("https://example.co.uk"     ).unwrap().domain_middle(), Some("example"));
assert_eq!(BetterUrl::parse("https://www.example.com"   ).unwrap().domain_middle(), Some("example"));
assert_eq!(BetterUrl::parse("https://www.example.co.uk" ).unwrap().domain_middle(), Some("example"));
assert_eq!(BetterUrl::parse("https://www.example.com."  ).unwrap().domain_middle(), Some("example"));
assert_eq!(BetterUrl::parse("https://www.example.co.uk.").unwrap().domain_middle(), Some("example"));
Source

pub fn reg_domain(&self) -> Option<&str>

The “registerable domain”, being the Self::domain_middle and Self::domain_suffix.

Specifically, if Self::host_details is HostDetails::Domain, return the substring of Url::host_str specified by DomainDetails::reg_domain_bounds.

§Examples
use better_url::*;
assert_eq!(BetterUrl::parse("https://example.com"       ).unwrap().reg_domain(), Some("example.com"  ));
assert_eq!(BetterUrl::parse("https://example.co.uk"     ).unwrap().reg_domain(), Some("example.co.uk"));
assert_eq!(BetterUrl::parse("https://www.example.com"   ).unwrap().reg_domain(), Some("example.com"  ));
assert_eq!(BetterUrl::parse("https://www.example.co.uk" ).unwrap().reg_domain(), Some("example.co.uk"));
assert_eq!(BetterUrl::parse("https://www.example.com."  ).unwrap().reg_domain(), Some("example.com"  ));
assert_eq!(BetterUrl::parse("https://www.example.co.uk.").unwrap().reg_domain(), Some("example.co.uk"));
Source

pub fn domain_suffix(&self) -> Option<&str>

The domain suffix, as defined by the public suffix list, not including any fully qualified domain name period.

Specifically, if Self::host_details is HostDetails::Domain, return the substring of Url::host_str specified by DomainDetails::domain_suffix_bounds.

§Examples
use better_url::*;
assert_eq!(BetterUrl::parse("https://example.com"       ).unwrap().domain_suffix(), Some("com"  ));
assert_eq!(BetterUrl::parse("https://example.co.uk"     ).unwrap().domain_suffix(), Some("co.uk"));
assert_eq!(BetterUrl::parse("https://www.example.com"   ).unwrap().domain_suffix(), Some("com"  ));
assert_eq!(BetterUrl::parse("https://www.example.co.uk" ).unwrap().domain_suffix(), Some("co.uk"));
assert_eq!(BetterUrl::parse("https://www.example.com."  ).unwrap().domain_suffix(), Some("com"  ));
assert_eq!(BetterUrl::parse("https://www.example.co.uk.").unwrap().domain_suffix(), Some("co.uk"));
Source

pub fn set_domain(&mut self, to: Option<&str>) -> Result<(), SetDomainError>

Sets the domain.

If this function returns Ok, then Self::domain returns the value passed into it.

§Errors

If the URL doesn’t have a domain host, to isn’t a domain, and/or to is a fully qualified domain, returns the error SetDomainError::Other.

§Examples
use better_url::*;

let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_domain(Some("example.com")).unwrap(); assert_eq!(url.host_str(), Some("example.com" ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_domain(Some("example.com")).unwrap(); assert_eq!(url.host_str(), Some("example.com" ));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_domain(Some("example.com")).unwrap(); assert_eq!(url.host_str(), Some("example.com" ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_domain(Some("example.com")).unwrap(); assert_eq!(url.host_str(), Some("example.com" ));

let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_domain(Some("example.com")).unwrap(); assert_eq!(url.host_str(), Some("example.com."));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_domain(Some("example.com")).unwrap(); assert_eq!(url.host_str(), Some("example.com."));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_domain(Some("example.com")).unwrap(); assert_eq!(url.host_str(), Some("example.com."));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_domain(Some("example.com")).unwrap(); assert_eq!(url.host_str(), Some("example.com."));
Source

pub fn set_subdomain( &mut self, to: Option<&str>, ) -> Result<(), SetSubdomainError>

Sets the subdomain.

If this function returns Ok, then Self::subdomain returns the value passed into it.

§Errors

If Self’s host isn’t a domain, returns the error SetSubdomainError::HostIsNotADomain.

If Self doesn’t have a reg domain, returns the error SetSubdomainError::MissingRegDomain.

§Examples
use better_url::*;

let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_subdomain(None       ).unwrap(); assert_eq!(url.host_str(), Some(    "example.com"   )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(0), suffix_start: Some(8 ), fqdn_period: None})));
let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_subdomain(Some("www")).unwrap(); assert_eq!(url.host_str(), Some("www.example.com"   )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: None})));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_subdomain(None       ).unwrap(); assert_eq!(url.host_str(), Some(    "example.com"   )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(0), suffix_start: Some(8 ), fqdn_period: None})));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_subdomain(Some("www")).unwrap(); assert_eq!(url.host_str(), Some("www.example.com"   )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: None})));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_subdomain(None       ).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk" )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(0), suffix_start: Some(8 ), fqdn_period: None})));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_subdomain(Some("www")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk" )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: None})));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_subdomain(None       ).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk" )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(0), suffix_start: Some(8 ), fqdn_period: None})));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_subdomain(Some("www")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk" )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: None})));

let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_subdomain(None       ).unwrap(); assert_eq!(url.host_str(), Some(    "example.com."  )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(0), suffix_start: Some(8 ), fqdn_period: Some(11)})));
let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_subdomain(Some("www")).unwrap(); assert_eq!(url.host_str(), Some("www.example.com."  )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: Some(15)})));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_subdomain(None       ).unwrap(); assert_eq!(url.host_str(), Some(    "example.com."  )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(0), suffix_start: Some(8 ), fqdn_period: Some(11)})));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_subdomain(Some("www")).unwrap(); assert_eq!(url.host_str(), Some("www.example.com."  )); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: Some(15)})));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_subdomain(None       ).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk.")); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(0), suffix_start: Some(8 ), fqdn_period: Some(13)})));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_subdomain(Some("www")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk.")); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: Some(17)})));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_subdomain(None       ).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk.")); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(0), suffix_start: Some(8 ), fqdn_period: Some(13)})));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_subdomain(Some("www")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk.")); assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: Some(17)})));
Source

pub fn set_not_domain_suffix( &mut self, to: Option<&str>, ) -> Result<(), SetNotDomainSuffixError>

Sets the “not domain suffix”.

If this function returns Ok, then Self::not_domain_suffix returns the value passed into it.

§Errors

If Self’s host isn’t a domain, returns the error SetSubdomainError::HostIsNotADomain.

If Self doesn’t have a domain suffix, returns the error SetNotDomainSuffixError::MissingDomainSuffix.

§Examples
use better_url::*;

let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_not_domain_suffix(None               ).unwrap(); assert_eq!(url.host_str(), Some(            "com"   ));
let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_not_domain_suffix(Some(    "example")).unwrap(); assert_eq!(url.host_str(), Some(    "example.com"   ));
let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_not_domain_suffix(Some("www.example")).unwrap(); assert_eq!(url.host_str(), Some("www.example.com"   ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_not_domain_suffix(None               ).unwrap(); assert_eq!(url.host_str(), Some(            "com"   ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_not_domain_suffix(Some(    "example")).unwrap(); assert_eq!(url.host_str(), Some(    "example.com"   ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_not_domain_suffix(Some("www.example")).unwrap(); assert_eq!(url.host_str(), Some("www.example.com"   ));

let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_not_domain_suffix(None               ).unwrap(); assert_eq!(url.host_str(), Some(            "co.uk" ));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_not_domain_suffix(Some(    "example")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk" ));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_not_domain_suffix(Some("www.example")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk" ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_not_domain_suffix(None               ).unwrap(); assert_eq!(url.host_str(), Some(            "co.uk" ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_not_domain_suffix(Some(    "example")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk" ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_not_domain_suffix(Some("www.example")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk" ));

let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_not_domain_suffix(None               ).unwrap(); assert_eq!(url.host_str(), Some(            "com."  ));
let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_not_domain_suffix(Some(    "example")).unwrap(); assert_eq!(url.host_str(), Some(    "example.com."  ));
let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_not_domain_suffix(Some("www.example")).unwrap(); assert_eq!(url.host_str(), Some("www.example.com."  ));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_not_domain_suffix(None               ).unwrap(); assert_eq!(url.host_str(), Some(            "com."  ));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_not_domain_suffix(Some(    "example")).unwrap(); assert_eq!(url.host_str(), Some(    "example.com."  ));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_not_domain_suffix(Some("www.example")).unwrap(); assert_eq!(url.host_str(), Some("www.example.com."  ));

let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_not_domain_suffix(None               ).unwrap(); assert_eq!(url.host_str(), Some(            "co.uk."));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_not_domain_suffix(Some(    "example")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk."));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_not_domain_suffix(Some("www.example")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk."));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_not_domain_suffix(None               ).unwrap(); assert_eq!(url.host_str(), Some(            "co.uk."));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_not_domain_suffix(Some(    "example")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk."));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_not_domain_suffix(Some("www.example")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk."));
Source

pub fn set_domain_middle( &mut self, to: Option<&str>, ) -> Result<(), SetDomainMiddleError>

Sets the domain middle.

If this function returns Ok, then Self::domain_middle returns the value passed into it.

§Errors

If Self’s host isn’t a domain, returns the error SetSubdomainError::HostIsNotADomain.

If Self doesn’t have a domain suffix, returns the error SetDomainMiddleError::MissingDomainSuffix.

§Examples
use better_url::*;

let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_domain_middle(None            ).unwrap(); assert_eq!(url.host_str(), Some(             "com"   ));
let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_domain_middle(Some("example2")).unwrap(); assert_eq!(url.host_str(), Some(    "example2.com"   ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_domain_middle(None            ).unwrap(); assert_eq!(url.host_str(), Some(         "www.com"   ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_domain_middle(Some("example2")).unwrap(); assert_eq!(url.host_str(), Some("www.example2.com"   ));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_domain_middle(None            ).unwrap(); assert_eq!(url.host_str(), Some(             "co.uk" ));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_domain_middle(Some("example2")).unwrap(); assert_eq!(url.host_str(), Some(    "example2.co.uk" ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_domain_middle(None            ).unwrap(); assert_eq!(url.host_str(), Some(         "www.co.uk" ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_domain_middle(Some("example2")).unwrap(); assert_eq!(url.host_str(), Some("www.example2.co.uk" ));

let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_domain_middle(None            ).unwrap(); assert_eq!(url.host_str(), Some(             "com."  ));
let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_domain_middle(Some("example2")).unwrap(); assert_eq!(url.host_str(), Some(    "example2.com."  ));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_domain_middle(None            ).unwrap(); assert_eq!(url.host_str(), Some(         "www.com."  ));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_domain_middle(Some("example2")).unwrap(); assert_eq!(url.host_str(), Some("www.example2.com."  ));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_domain_middle(None            ).unwrap(); assert_eq!(url.host_str(), Some(             "co.uk."));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_domain_middle(Some("example2")).unwrap(); assert_eq!(url.host_str(), Some(    "example2.co.uk."));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_domain_middle(None            ).unwrap(); assert_eq!(url.host_str(), Some(         "www.co.uk."));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_domain_middle(Some("example2")).unwrap(); assert_eq!(url.host_str(), Some("www.example2.co.uk."));
Source

pub fn set_reg_domain( &mut self, to: Option<&str>, ) -> Result<(), SetRegDomainError>

Sets the registerable domain.

If this function returns Ok, then Self::reg_domain returns the value passed into it.

§Errors

If Self’s host isn’t a domain, returns the error SetRegDomainError::HostIsNotADomain.

§Examples
use better_url::*;

let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_reg_domain(None                 ).unwrap_err();
let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_reg_domain(Some(        "com"  )).unwrap(); assert_eq!(url.host_str(), Some(            "com"   ));
let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_reg_domain(Some("example.com"  )).unwrap(); assert_eq!(url.host_str(), Some(    "example.com"   ));
let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_reg_domain(Some(        "co.uk")).unwrap(); assert_eq!(url.host_str(), Some(            "co.uk" ));
let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_reg_domain(Some("example.co.uk")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk" ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_reg_domain(None                 ).unwrap(); assert_eq!(url.host_str(), Some(            "www"   ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_reg_domain(Some(        "com"  )).unwrap(); assert_eq!(url.host_str(), Some(        "www.com"   ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_reg_domain(Some("example.com"  )).unwrap(); assert_eq!(url.host_str(), Some("www.example.com"   ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_reg_domain(Some(        "co.uk")).unwrap(); assert_eq!(url.host_str(), Some(        "www.co.uk" ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_reg_domain(Some("example.co.uk")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk" ));

let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_reg_domain(None                 ).unwrap_err();
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_reg_domain(Some(        "com"  )).unwrap(); assert_eq!(url.host_str(), Some(            "com"   ));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_reg_domain(Some("example.com"  )).unwrap(); assert_eq!(url.host_str(), Some(    "example.com"   ));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_reg_domain(Some(        "co.uk")).unwrap(); assert_eq!(url.host_str(), Some(            "co.uk" ));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_reg_domain(Some("example.co.uk")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk" ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_reg_domain(None                 ).unwrap(); assert_eq!(url.host_str(), Some(            "www"   ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_reg_domain(Some(        "com"  )).unwrap(); assert_eq!(url.host_str(), Some(        "www.com"   ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_reg_domain(Some("example.com"  )).unwrap(); assert_eq!(url.host_str(), Some("www.example.com"   ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_reg_domain(Some(        "co.uk")).unwrap(); assert_eq!(url.host_str(), Some(        "www.co.uk" ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_reg_domain(Some("example.co.uk")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk" ));

let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_reg_domain(None                 ).unwrap(); assert_eq!(url.host_str(), Some(               "."  ));
let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_reg_domain(Some(        "com"  )).unwrap(); assert_eq!(url.host_str(), Some(            "com."  ));
let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_reg_domain(Some("example.com"  )).unwrap(); assert_eq!(url.host_str(), Some(    "example.com."  ));
let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_reg_domain(Some(        "co.uk")).unwrap(); assert_eq!(url.host_str(), Some(            "co.uk."));
let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_reg_domain(Some("example.co.uk")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk."));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_reg_domain(None                 ).unwrap(); assert_eq!(url.host_str(), Some(             "www." ));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_reg_domain(Some(        "com"  )).unwrap(); assert_eq!(url.host_str(), Some(        "www.com."  ));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_reg_domain(Some("example.com"  )).unwrap(); assert_eq!(url.host_str(), Some("www.example.com."  ));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_reg_domain(Some(        "co.uk")).unwrap(); assert_eq!(url.host_str(), Some(        "www.co.uk."));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_reg_domain(Some("example.co.uk")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk."));

let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_reg_domain(None                 ).unwrap(); assert_eq!(url.host_str(), Some(               "."  ));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_reg_domain(Some(        "com"  )).unwrap(); assert_eq!(url.host_str(), Some(            "com."  ));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_reg_domain(Some("example.com"  )).unwrap(); assert_eq!(url.host_str(), Some(    "example.com."  ));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_reg_domain(Some(        "co.uk")).unwrap(); assert_eq!(url.host_str(), Some(            "co.uk."));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_reg_domain(Some("example.co.uk")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk."));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_reg_domain(None                 ).unwrap(); assert_eq!(url.host_str(), Some(            "www."  ));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_reg_domain(Some(        "com"  )).unwrap(); assert_eq!(url.host_str(), Some(        "www.com."  ));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_reg_domain(Some("example.com"  )).unwrap(); assert_eq!(url.host_str(), Some("www.example.com."  ));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_reg_domain(Some(        "co.uk")).unwrap(); assert_eq!(url.host_str(), Some(        "www.co.uk."));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_reg_domain(Some("example.co.uk")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk."));
Source

pub fn set_domain_suffix( &mut self, to: Option<&str>, ) -> Result<(), SetDomainSuffixError>

Sets the domain suffix.

If this function returns Ok, then Self::domain_suffix returns the value passed into it.

§Errors

If Self’s host isn’t a domain, returns the error SetDomainSuffixError::HostIsNotADomain.

§Examples
use better_url::*;

let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_domain_suffix(None         ).unwrap(); assert_eq!(url.host_str(), Some(    "example"       ));
let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_domain_suffix(Some("com"  )).unwrap(); assert_eq!(url.host_str(), Some(    "example.com"   ));
let mut url = BetterUrl::parse(    "https://example.com"   ).unwrap(); url.set_domain_suffix(Some("co.uk")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk" ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_domain_suffix(None         ).unwrap(); assert_eq!(url.host_str(), Some("www.example"       ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_domain_suffix(Some("com"  )).unwrap(); assert_eq!(url.host_str(), Some("www.example.com"   ));
let mut url = BetterUrl::parse("https://www.example.com"   ).unwrap(); url.set_domain_suffix(Some("co.uk")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk" ));

let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_domain_suffix(None         ).unwrap(); assert_eq!(url.host_str(), Some(    "example"       ));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_domain_suffix(Some("com"  )).unwrap(); assert_eq!(url.host_str(), Some(    "example.com"   ));
let mut url = BetterUrl::parse(    "https://example.co.uk" ).unwrap(); url.set_domain_suffix(Some("co.uk")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk" ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_domain_suffix(None         ).unwrap(); assert_eq!(url.host_str(), Some("www.example"       ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_domain_suffix(Some("com"  )).unwrap(); assert_eq!(url.host_str(), Some("www.example.com"   ));
let mut url = BetterUrl::parse("https://www.example.co.uk" ).unwrap(); url.set_domain_suffix(Some("co.uk")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk" ));

let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_domain_suffix(None         ).unwrap(); assert_eq!(url.host_str(), Some(    "example."      ));
let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_domain_suffix(Some("com"  )).unwrap(); assert_eq!(url.host_str(), Some(    "example.com."  ));
let mut url = BetterUrl::parse(    "https://example.com."  ).unwrap(); url.set_domain_suffix(Some("co.uk")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk."));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_domain_suffix(None         ).unwrap(); assert_eq!(url.host_str(), Some("www.example."      ));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_domain_suffix(Some("com"  )).unwrap(); assert_eq!(url.host_str(), Some("www.example.com."  ));
let mut url = BetterUrl::parse("https://www.example.com."  ).unwrap(); url.set_domain_suffix(Some("co.uk")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk."));

let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_domain_suffix(None         ).unwrap(); assert_eq!(url.host_str(), Some(    "example."      ));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_domain_suffix(Some("com"  )).unwrap(); assert_eq!(url.host_str(), Some(    "example.com."  ));
let mut url = BetterUrl::parse(    "https://example.co.uk.").unwrap(); url.set_domain_suffix(Some("co.uk")).unwrap(); assert_eq!(url.host_str(), Some(    "example.co.uk."));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_domain_suffix(None         ).unwrap(); assert_eq!(url.host_str(), Some("www.example."      ));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_domain_suffix(Some("com"  )).unwrap(); assert_eq!(url.host_str(), Some("www.example.com."  ));
let mut url = BetterUrl::parse("https://www.example.co.uk.").unwrap(); url.set_domain_suffix(Some("co.uk")).unwrap(); assert_eq!(url.host_str(), Some("www.example.co.uk."));
Source

pub fn set_fqdn(&mut self, to: bool) -> Result<(), SetFqdnError>

Sets the fully qualified domain name period.

§Errors

If self doesn’t have a host, returns the error SetFqdnError::NoHost.

If the host isn’t a domain, returns the error SetFqdnError::HostIsNotADomain.

§Examples
use better_url::*;
let mut url = BetterUrl::parse("https://example.com").unwrap();

url.set_fqdn(false).unwrap();
assert_eq!(url.host_str(), Some("example.com"));

url.set_fqdn(true).unwrap();
assert_eq!(url.host_str(), Some("example.com."));

url.set_fqdn(true).unwrap();
assert_eq!(url.host_str(), Some("example.com."));

url.set_fqdn(false).unwrap();
assert_eq!(url.host_str(), Some("example.com"));
Source§

impl BetterUrl

Source

pub fn set_query(&mut self, query: Option<&str>)

Source

pub fn query_pairs_mut(&mut self) -> Serializer<'_, UrlQuery<'_>>

Source

pub fn raw_query_pairs( &self, ) -> Option<impl Iterator<Item = (&str, Option<&str>)>>

An iterator over query parameters without percent decoding anything.

§Examples
use better_url::*;

let url = BetterUrl::parse("https://example.com?a=1&%61=2&a=3&b=%41&%62=%42&b=%43").unwrap();

let mut raw_query_pairs = url.raw_query_pairs().unwrap();

assert_eq!(raw_query_pairs.next(), Some(("a"  , Some("1"))));
assert_eq!(raw_query_pairs.next(), Some(("%61", Some("2"))));
assert_eq!(raw_query_pairs.next(), Some(("a"  , Some("3"))));
assert_eq!(raw_query_pairs.next(), Some(("b"  , Some("%41"))));
assert_eq!(raw_query_pairs.next(), Some(("%62", Some("%42"))));
assert_eq!(raw_query_pairs.next(), Some(("b"  , Some("%43"))));
Source

pub fn raw_query_param<'a>( &'a self, name: &str, index: usize, ) -> Option<Option<Option<&'a str>>>

Get the selected query parameter without percent decoding the value.

For matching, the names are percent decoded. So a %61=a query parameter is selectable with a name of a.

§Examples
use better_url::*;

let url = BetterUrl::parse("https://example.com?a=1&%61=2&a=3&b=%41&%62=%42&b=%43").unwrap();

assert_eq!(url.raw_query_param("a", 0), Some(Some(Some("1"))));
assert_eq!(url.raw_query_param("a", 1), Some(Some(Some("2"))));
assert_eq!(url.raw_query_param("a", 2), Some(Some(Some("3"))));
assert_eq!(url.raw_query_param("b", 0), Some(Some(Some("%41"))));
assert_eq!(url.raw_query_param("b", 1), Some(Some(Some("%42"))));
assert_eq!(url.raw_query_param("b", 2), Some(Some(Some("%43"))));
Source

pub fn has_raw_query_param(&self, name: &str, index: usize) -> bool

Return true if Self::raw_query_param would return Some(Some(_)), but doesn’t do any unnecessary computation.

Please note that this returns true even if the query param has no value.

§Examples
use better_url::*;

let url = BetterUrl::parse("https://example.com?a=1&%61=2&a&%61=4").unwrap();

assert!( url.has_raw_query_param("a", 0));
assert!( url.has_raw_query_param("a", 1));
assert!(!url.has_raw_query_param("a", 2));
assert!(!url.has_raw_query_param("a", 3));
assert!(!url.has_raw_query_param("a", 4));
Source

pub fn has_query_param(&self, name: &str, index: usize) -> bool

Return true if Self::query_param would return Some(Some(_)), but doesn’t do any unnecessary computation.

For matching, the names are percent decoded. So a %61=a query parameter is selectable with a name of a.

Please note that this returns true even if the query param has no value.

§Examples
use better_url::*;

let url = BetterUrl::parse("https://example.com?a=1&%61=2&a&%61=4").unwrap();

assert!( url.has_query_param("a", 0));
assert!( url.has_query_param("a", 1));
assert!( url.has_query_param("a", 2));
assert!( url.has_query_param("a", 3));
assert!(!url.has_query_param("a", 4));
Source

pub fn query_param<'a>( &'a self, name: &str, index: usize, ) -> Option<Option<Option<Cow<'a, str>>>>

Get the selected query parameter.

For matching, the names are percent decoded. So a %61=a query parameter is selectable with a name of a.

First Option is if there’s a query.

Second Option is if there’s a query parameter with the specified name.

Third Option is if it has a value.

§Examples
use better_url::*;

let url = BetterUrl::parse("https://example.com?a=2&b=3&a=4&c").unwrap();

assert_eq!(url.query_param("a", 0), Some(Some(Some("2".into()))));
assert_eq!(url.query_param("a", 1), Some(Some(Some("4".into()))));
assert_eq!(url.query_param("a", 2), Some(None));
assert_eq!(url.query_param("b", 0), Some(Some(Some("3".into()))));
assert_eq!(url.query_param("b", 1), Some(None));
assert_eq!(url.query_param("c", 0), Some(Some(None)));
assert_eq!(url.query_param("c", 1), Some(None));


let url = BetterUrl::parse("https://example.com").unwrap();

assert_eq!(url.query_param("a", 0), None);
assert_eq!(url.query_param("a", 1), None);


let url = BetterUrl::parse("https://example.com?a=1&%61=2&a=3&b=%41&%62=%42&b=%43").unwrap();

assert_eq!(url.query_param("a", 0), Some(Some(Some("1".into()))));
assert_eq!(url.query_param("a", 1), Some(Some(Some("2".into()))));
assert_eq!(url.query_param("a", 2), Some(Some(Some("3".into()))));
assert_eq!(url.query_param("b", 0), Some(Some(Some("A".into()))));
assert_eq!(url.query_param("b", 1), Some(Some(Some("B".into()))));
assert_eq!(url.query_param("b", 2), Some(Some(Some("C".into()))));
Source

pub fn set_query_param( &mut self, name: &str, index: usize, to: Option<Option<&str>>, ) -> Result<(), SetQueryParamError>

Set the selected query parameter.

For matching, the names are percent decoded. So a %61=a query parameter is selectable with a name of a.

If there are N query parameters named name and index is N, appends a new query parameter to the end.

For performance reasons, resulting empty queries are replaced with None.

§Errors

If index is above the number of matched query params, returns the error SetQueryParamError::QueryParamIndexNotFound.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com").unwrap();

url.set_query_param("a", 0, None).unwrap();
assert_eq!(url.query(), None);
url.set_query_param("a", 0, Some(Some("2"))).unwrap();
assert_eq!(url.query(), Some("a=2"));
url.set_query_param("a", 0, Some(Some("3"))).unwrap();
assert_eq!(url.query(), Some("a=3"));
url.set_query_param("a", 1, Some(Some("4"))).unwrap();
assert_eq!(url.query(), Some("a=3&a=4"));
url.set_query_param("a", 3, Some(Some("5"))).unwrap_err();
assert_eq!(url.query(), Some("a=3&a=4"));
url.set_query_param("a", 0, Some(None)).unwrap();
assert_eq!(url.query(), Some("a&a=4"));
url.set_query_param("a", 0, None).unwrap();
assert_eq!(url.query(), Some("a=4"));
url.set_query_param("a", 0, None).unwrap();
assert_eq!(url.query(), None);

// Inserting adjacent query params
url.set_query_param("a", 0, Some(Some("2&b=3"))).unwrap();
assert_eq!(url.query(), Some("a=2%26b%3D3"));

// Setting the fragment
url.set_query_param("a", 0, Some(Some("2#123"))).unwrap();
assert_eq!(url.query(), Some("a=2%23123"));
assert_eq!(url.fragment(), None);
url.set_query_param("a", 0, Some(Some("3"))).unwrap();
assert_eq!(url.query(), Some("a=3"));
assert_eq!(url.fragment(), None);


// Empty query optimization.
let mut url = BetterUrl::parse("https://example.com?").unwrap();

assert_eq!(url.query(), Some(""));
url.set_query_param("a", 0, None).unwrap();
assert_eq!(url.query(), None);
Source

pub fn set_raw_query_param( &mut self, name: &str, index: usize, to: Option<Option<&str>>, ) -> Result<(), SetQueryParamError>

Sets the selected query parameter, without ensuring either the name or the value are valid.

For matching, the names are percent decoded. So a %61=a query parameter is selectable with a name of a.

If there are N query parameters named name and index is N, appends a new query parameter to the end.

For performance reasons, resulting empty queries are replaced with None.

Useful in combination with Self::raw_query_param for transplanting values without decoding then re-encoding them.

PLEASE note that if name and/or value contain special characters like =, &, etc. this will give incoherent results! ONLY use this for directly transplanting from and to query params.

§Errors

If index is above the number of matched query params, returns the error SetQueryParamError::QueryParamIndexNotFound.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com").unwrap();

// Normal use
url.set_raw_query_param("a", 0, None).unwrap();
assert_eq!(url.query(), None);
url.set_raw_query_param("a", 0, Some(Some("2"))).unwrap();
assert_eq!(url.query(), Some("a=2"));
url.set_raw_query_param("a", 0, Some(Some("3"))).unwrap();
assert_eq!(url.query(), Some("a=3"));
url.set_raw_query_param("a", 1, Some(Some("4"))).unwrap();
assert_eq!(url.query(), Some("a=3&a=4"));
url.set_raw_query_param("a", 3, Some(Some("5"))).unwrap_err();
assert_eq!(url.query(), Some("a=3&a=4"));
url.set_raw_query_param("a", 0, Some(None)).unwrap();
assert_eq!(url.query(), Some("a&a=4"));
url.set_raw_query_param("a", 0, None).unwrap();
assert_eq!(url.query(), Some("a=4"));
url.set_raw_query_param("a", 0, None).unwrap();
assert_eq!(url.query(), None);

// Inserting adjacent query params
url.set_raw_query_param("a", 0, Some(Some("2&b=3"))).unwrap();
assert_eq!(url.query(), Some("a=2&b=3"));

// Failing to set the fragment because [`Url::set_query`] refuses to.
url.set_raw_query_param("a", 0, Some(Some("2#123"))).unwrap();
assert_eq!(url.query(), Some("a=2%23123&b=3"));
assert_eq!(url.fragment(), None);
url.set_raw_query_param("a", 0, Some(Some("3"))).unwrap();
assert_eq!(url.query(), Some("a=3&b=3"));
assert_eq!(url.fragment(), None);


// Empty query optimization.
let mut url = BetterUrl::parse("https://example.com?").unwrap();

assert_eq!(url.query(), Some(""));
url.set_raw_query_param("a", 0, None).unwrap();
assert_eq!(url.query(), None);
Source

pub fn rename_query_param( &mut self, name: &str, index: usize, to: &str, ) -> Result<(), RenameQueryParamError>

Rename the specified query parameter to the specified name.

§Errors

If to contains a &, =, or #, returns the error RenameQueryParamError::InvalidName.

If Url::query is None, returns the error RenameQueryParamError::NoQuery.

If the specified query param isn’t found, returns the error RenameQueryParamError::QueryParamNotFound.

§Examples
use better_url::*;

let mut url = BetterUrl::parse("https://example.com?a=1&%61=2&a=3").unwrap();

url.rename_query_param("a", 1, "b").unwrap();
assert_eq!(url.query(), Some("a=1&b=2&a=3"));

url.rename_query_param("a", 1, "b").unwrap();
assert_eq!(url.query(), Some("a=1&b=2&b=3"));

url.rename_query_param("a", 1, "b").unwrap_err();
assert_eq!(url.query(), Some("a=1&b=2&b=3"));
Source§

impl BetterUrl

Source

pub fn parse(value: &str) -> Result<BetterUrl, <BetterUrl as FromStr>::Err>

Parse a URL.

§Errors

If the call to Url::parse returns an error, that error is returned.

§Examples
use better_url::*;
let url = BetterUrl::parse("https://example.com").unwrap();
Source

pub fn host_details(&self) -> Option<&HostDetails>

Get the contained HostDetails.

§Examples
use better_url::*;
let url = BetterUrl::parse("https://example.com").unwrap();

assert_eq!(url.host_details(), Some(&HostDetails::Domain(DomainDetails {middle_start: Some(0), suffix_start: Some(8), fqdn_period: None})));

let url = BetterUrl::parse("https://127.0.0.1").unwrap();

assert_eq!(url.host_details(), Some(&HostDetails::Ipv4(Ipv4Details {})));

let url = BetterUrl::parse("https://[::1]").unwrap();

assert_eq!(url.host_details(), Some(&HostDetails::Ipv6(Ipv6Details {})));
Source

pub fn domain_details(&self) -> Option<&DomainDetails>

If Self::host_details returns HostDetails::Domain, return it.

use better_url::*;
let url = BetterUrl::parse("https://example.com").unwrap();

assert_eq!(url.domain_details(), Some(&DomainDetails {middle_start: Some(0), suffix_start: Some(8), fqdn_period: None}));
assert_eq!(url.ipv4_details  (), None);
assert_eq!(url.ipv6_details  (), None);
Source

pub fn ipv4_details(&self) -> Option<&Ipv4Details>

If Self::host_details returns HostDetails::Ipv4, return it.

use better_url::*;
let url = BetterUrl::parse("https://127.0.0.1").unwrap();

assert_eq!(url.domain_details(), None);
assert_eq!(url.ipv4_details  (), Some(&Ipv4Details {}));
assert_eq!(url.ipv6_details  (), None);
Source

pub fn ipv6_details(&self) -> Option<&Ipv6Details>

If Self::host_details returns HostDetails::Ipv6, return it.

use better_url::*;
let url = BetterUrl::parse("https://[::1]").unwrap();

assert_eq!(url.domain_details(), None);
assert_eq!(url.ipv4_details  (), None);
assert_eq!(url.ipv6_details  (), Some(&Ipv6Details {}));
Source

pub fn normalized_host(&self) -> Option<&str>

Url::host_str with any www. prefix and . suffix removed.

Source

pub fn set_scheme(&mut self, scheme: &str) -> Result<(), SetSchemeError>

Url::set_scheme.

§Errors

If the call to Url::set_scheme returns an error, returns the error SetSchemeError.

Source

pub fn set_username(&mut self, username: &str) -> Result<(), SetUsernameError>

Url::set_username.

§Errors

If the call to Url::set_username returns an error, returns the error SetUsernameError.

Source

pub fn set_password( &mut self, password: Option<&str>, ) -> Result<(), SetPasswordError>

Url::set_password.

§Errors

If the call to Url::set_password returns an error, returns the error SetPasswordError.

Source

pub fn set_host(&mut self, host: Option<&str>) -> Result<(), SetHostError>

Url::set_host.

§Errors

If the call to Url::set_host returns an error, the error is returned..

Source

pub fn set_ip_host(&mut self, address: IpAddr) -> Result<(), SetIpHostError>

Url::set_ip_host.

§Errors

If the call to Url::set_ip_host returns an error, returns the error SetIpHostError.

Source

pub fn set_port(&mut self, port: Option<u16>) -> Result<(), SetPortError>

Url::set_port.

§Errors

If the call to Url::set_port returns an error, returns the error SetPortError.

Source

pub fn set_fragment(&mut self, fragment: Option<&str>)

Methods from Deref<Target = Url>§

Source

pub fn join(&self, input: &str) -> Result<Url, ParseError>

Parse a string as an URL, with this URL as the base URL.

The inverse of this is make_relative.

§Notes
  • A trailing slash is significant. Without it, the last path component is considered to be a “file” name to be removed to get at the “directory” that is used as the base.
  • A scheme relative special URL as input replaces everything in the base URL after the scheme.
  • An absolute URL (with a scheme) as input replaces the whole base URL (even the scheme).
§Examples
use url::Url;

// Base without a trailing slash
let base = Url::parse("https://example.net/a/b.html")?;
let url = base.join("c.png")?;
assert_eq!(url.as_str(), "https://example.net/a/c.png");  // Not /a/b.html/c.png

// Base with a trailing slash
let base = Url::parse("https://example.net/a/b/")?;
let url = base.join("c.png")?;
assert_eq!(url.as_str(), "https://example.net/a/b/c.png");

// Input as scheme relative special URL
let base = Url::parse("https://alice.com/a")?;
let url = base.join("//eve.com/b")?;
assert_eq!(url.as_str(), "https://eve.com/b");

// Input as base url relative special URL
let base = Url::parse("https://alice.com/a")?;
let url = base.join("/v1/meta")?;
assert_eq!(url.as_str(), "https://alice.com/v1/meta");

// Input as absolute URL
let base = Url::parse("https://alice.com/a")?;
let url = base.join("http://eve.com/b")?;
assert_eq!(url.as_str(), "http://eve.com/b");  // http instead of https
§Errors

If the function can not parse an URL from the given string with this URL as the base URL, a ParseError variant will be returned.

Source

pub fn make_relative(&self, url: &Url) -> Option<String>

Creates a relative URL if possible, with this URL as the base URL.

This is the inverse of join.

§Examples
use url::Url;

let base = Url::parse("https://example.net/a/b.html")?;
let url = Url::parse("https://example.net/a/c.png")?;
let relative = base.make_relative(&url);
assert_eq!(relative.as_ref().map(|s| s.as_str()), Some("c.png"));

let base = Url::parse("https://example.net/a/b/")?;
let url = Url::parse("https://example.net/a/b/c.png")?;
let relative = base.make_relative(&url);
assert_eq!(relative.as_ref().map(|s| s.as_str()), Some("c.png"));

let base = Url::parse("https://example.net/a/b/")?;
let url = Url::parse("https://example.net/a/d/c.png")?;
let relative = base.make_relative(&url);
assert_eq!(relative.as_ref().map(|s| s.as_str()), Some("../d/c.png"));

let base = Url::parse("https://example.net/a/b.html?c=d")?;
let url = Url::parse("https://example.net/a/b.html?e=f")?;
let relative = base.make_relative(&url);
assert_eq!(relative.as_ref().map(|s| s.as_str()), Some("?e=f"));
§Errors

If this URL can’t be a base for the given URL, None is returned. This is for example the case if the scheme, host or port are not the same.

Source

pub fn as_str(&self) -> &str

Return the serialization of this URL.

This is fast since that serialization is already stored in the Url struct.

§Examples
use url::Url;

let url_str = "https://example.net/";
let url = Url::parse(url_str)?;
assert_eq!(url.as_str(), url_str);
Source

pub fn origin(&self) -> Origin

Return the origin of this URL (https://url.spec.whatwg.org/#origin)

Note: this returns an opaque origin for file: URLs, which causes url.origin() != url.origin().

§Examples

URL with ftp scheme:

use url::{Host, Origin, Url};

let url = Url::parse("ftp://example.com/foo")?;
assert_eq!(url.origin(),
           Origin::Tuple("ftp".into(),
                         Host::Domain("example.com".into()),
                         21));

URL with blob scheme:

use url::{Host, Origin, Url};

let url = Url::parse("blob:https://example.com/foo")?;
assert_eq!(url.origin(),
           Origin::Tuple("https".into(),
                         Host::Domain("example.com".into()),
                         443));

URL with file scheme:

use url::{Host, Origin, Url};

let url = Url::parse("file:///tmp/foo")?;
assert!(!url.origin().is_tuple());

let other_url = Url::parse("file:///tmp/foo")?;
assert!(url.origin() != other_url.origin());

URL with other scheme:

use url::{Host, Origin, Url};

let url = Url::parse("foo:bar")?;
assert!(!url.origin().is_tuple());
Source

pub fn scheme(&self) -> &str

Return the scheme of this URL, lower-cased, as an ASCII string without the ‘:’ delimiter.

§Examples
use url::Url;

let url = Url::parse("file:///tmp/foo")?;
assert_eq!(url.scheme(), "file");
Source

pub fn is_special(&self) -> bool

Return whether the URL is special (has a special scheme)

§Examples
use url::Url;

assert!(Url::parse("http:///tmp/foo")?.is_special());
assert!(Url::parse("file:///tmp/foo")?.is_special());
assert!(!Url::parse("moz:///tmp/foo")?.is_special());
Source

pub fn has_authority(&self) -> bool

Return whether the URL has an ‘authority’, which can contain a username, password, host, and port number.

URLs that do not are either path-only like unix:/run/foo.socket or cannot-be-a-base like data:text/plain,Stuff.

See also the authority method.

§Examples
use url::Url;

let url = Url::parse("ftp://rms@example.com")?;
assert!(url.has_authority());

let url = Url::parse("unix:/run/foo.socket")?;
assert!(!url.has_authority());

let url = Url::parse("data:text/plain,Stuff")?;
assert!(!url.has_authority());
Source

pub fn authority(&self) -> &str

Return the authority of this URL as an ASCII string.

Non-ASCII domains are punycode-encoded per IDNA if this is the host of a special URL, or percent encoded for non-special URLs. IPv6 addresses are given between [ and ] brackets. Ports are omitted if they match the well known port of a special URL.

Username and password are percent-encoded.

See also the has_authority method.

§Examples
use url::Url;

let url = Url::parse("unix:/run/foo.socket")?;
assert_eq!(url.authority(), "");
let url = Url::parse("file:///tmp/foo")?;
assert_eq!(url.authority(), "");
let url = Url::parse("https://user:password@example.com/tmp/foo")?;
assert_eq!(url.authority(), "user:password@example.com");
let url = Url::parse("irc://àlex.рф.example.com:6667/foo")?;
assert_eq!(url.authority(), "%C3%A0lex.%D1%80%D1%84.example.com:6667");
let url = Url::parse("http://àlex.рф.example.com:80/foo")?;
assert_eq!(url.authority(), "xn--lex-8ka.xn--p1ai.example.com");
Source

pub fn cannot_be_a_base(&self) -> bool

Return whether this URL is a cannot-be-a-base URL, meaning that parsing a relative URL string with this URL as the base will return an error.

This is the case if the scheme and : delimiter are not followed by a / slash, as is typically the case of data: and mailto: URLs.

§Examples
use url::Url;

let url = Url::parse("ftp://rms@example.com")?;
assert!(!url.cannot_be_a_base());

let url = Url::parse("unix:/run/foo.socket")?;
assert!(!url.cannot_be_a_base());

let url = Url::parse("data:text/plain,Stuff")?;
assert!(url.cannot_be_a_base());
Source

pub fn username(&self) -> &str

Return the username for this URL (typically the empty string) as a percent-encoded ASCII string.

§Examples
use url::Url;

let url = Url::parse("ftp://rms@example.com")?;
assert_eq!(url.username(), "rms");

let url = Url::parse("ftp://:secret123@example.com")?;
assert_eq!(url.username(), "");

let url = Url::parse("https://example.com")?;
assert_eq!(url.username(), "");
Source

pub fn password(&self) -> Option<&str>

Return the password for this URL, if any, as a percent-encoded ASCII string.

§Examples
use url::Url;

let url = Url::parse("ftp://rms:secret123@example.com")?;
assert_eq!(url.password(), Some("secret123"));

let url = Url::parse("ftp://:secret123@example.com")?;
assert_eq!(url.password(), Some("secret123"));

let url = Url::parse("ftp://rms@example.com")?;
assert_eq!(url.password(), None);

let url = Url::parse("https://example.com")?;
assert_eq!(url.password(), None);
Source

pub fn has_host(&self) -> bool

Equivalent to url.host().is_some().

§Examples
use url::Url;

let url = Url::parse("ftp://rms@example.com")?;
assert!(url.has_host());

let url = Url::parse("unix:/run/foo.socket")?;
assert!(!url.has_host());

let url = Url::parse("data:text/plain,Stuff")?;
assert!(!url.has_host());
Source

pub fn host_str(&self) -> Option<&str>

Return the string representation of the host (domain or IP address) for this URL, if any.

Non-ASCII domains are punycode-encoded per IDNA if this is the host of a special URL, or percent encoded for non-special URLs. IPv6 addresses are given between [ and ] brackets.

Cannot-be-a-base URLs (typical of data: and mailto:) and some file: URLs don’t have a host.

See also the host method.

§Examples
use url::Url;

let url = Url::parse("https://127.0.0.1/index.html")?;
assert_eq!(url.host_str(), Some("127.0.0.1"));

let url = Url::parse("https://subdomain.example.com")?;
assert_eq!(url.host_str(), Some("subdomain.example.com"));

let url = Url::parse("ftp://rms@example.com")?;
assert_eq!(url.host_str(), Some("example.com"));

let url = Url::parse("unix:/run/foo.socket")?;
assert_eq!(url.host_str(), None);

let url = Url::parse("data:text/plain,Stuff")?;
assert_eq!(url.host_str(), None);
Source

pub fn host(&self) -> Option<Host<&str>>

Return the parsed representation of the host for this URL. Non-ASCII domain labels are punycode-encoded per IDNA if this is the host of a special URL, or percent encoded for non-special URLs.

Cannot-be-a-base URLs (typical of data: and mailto:) and some file: URLs don’t have a host.

See also the host_str method.

§Examples
use url::Url;

let url = Url::parse("https://127.0.0.1/index.html")?;
assert!(url.host().is_some());

let url = Url::parse("ftp://rms@example.com")?;
assert!(url.host().is_some());

let url = Url::parse("unix:/run/foo.socket")?;
assert!(url.host().is_none());

let url = Url::parse("data:text/plain,Stuff")?;
assert!(url.host().is_none());
Source

pub fn domain(&self) -> Option<&str>

If this URL has a host and it is a domain name (not an IP address), return it. Non-ASCII domains are punycode-encoded per IDNA if this is the host of a special URL, or percent encoded for non-special URLs.

§Examples
use url::Url;

let url = Url::parse("https://127.0.0.1/")?;
assert_eq!(url.domain(), None);

let url = Url::parse("mailto:rms@example.net")?;
assert_eq!(url.domain(), None);

let url = Url::parse("https://example.com/")?;
assert_eq!(url.domain(), Some("example.com"));

let url = Url::parse("https://subdomain.example.com/")?;
assert_eq!(url.domain(), Some("subdomain.example.com"));
Source

pub fn port(&self) -> Option<u16>

Return the port number for this URL, if any.

Note that default port numbers are never reflected by the serialization, use the port_or_known_default() method if you want a default port number returned.

§Examples
use url::Url;

let url = Url::parse("https://example.com")?;
assert_eq!(url.port(), None);

let url = Url::parse("https://example.com:443/")?;
assert_eq!(url.port(), None);

let url = Url::parse("ssh://example.com:22")?;
assert_eq!(url.port(), Some(22));
Source

pub fn port_or_known_default(&self) -> Option<u16>

Return the port number for this URL, or the default port number if it is known.

This method only knows the default port number of the http, https, ws, wss and ftp schemes.

For URLs in these schemes, this method always returns Some(_). For other schemes, it is the same as Url::port().

§Examples
use url::Url;

let url = Url::parse("foo://example.com")?;
assert_eq!(url.port_or_known_default(), None);

let url = Url::parse("foo://example.com:1456")?;
assert_eq!(url.port_or_known_default(), Some(1456));

let url = Url::parse("https://example.com")?;
assert_eq!(url.port_or_known_default(), Some(443));
Source

pub fn socket_addrs( &self, default_port_number: impl Fn() -> Option<u16>, ) -> Result<Vec<SocketAddr>, Error>

Resolve a URL’s host and port number to SocketAddr.

If the URL has the default port number of a scheme that is unknown to this library, default_port_number provides an opportunity to provide the actual port number. In non-example code this should be implemented either simply as || None, or by matching on the URL’s .scheme().

If the host is a domain, it is resolved using the standard library’s DNS support.

§Examples
let url = url::Url::parse("https://example.net/").unwrap();
let addrs = url.socket_addrs(|| None).unwrap();
std::net::TcpStream::connect(&*addrs)
/// With application-specific known default port numbers
fn socket_addrs(url: url::Url) -> std::io::Result<Vec<std::net::SocketAddr>> {
    url.socket_addrs(|| match url.scheme() {
        "socks5" | "socks5h" => Some(1080),
        _ => None,
    })
}
Source

pub fn path(&self) -> &str

Return the path for this URL, as a percent-encoded ASCII string. For cannot-be-a-base URLs, this is an arbitrary string that doesn’t start with ‘/’. For other URLs, this starts with a ‘/’ slash and continues with slash-separated path segments.

§Examples
use url::{Url, ParseError};

let url = Url::parse("https://example.com/api/versions?page=2")?;
assert_eq!(url.path(), "/api/versions");

let url = Url::parse("https://example.com")?;
assert_eq!(url.path(), "/");

let url = Url::parse("https://example.com/countries/việt nam")?;
assert_eq!(url.path(), "/countries/vi%E1%BB%87t%20nam");
Source

pub fn path_segments(&self) -> Option<Split<'_, char>>

Unless this URL is cannot-be-a-base, return an iterator of ‘/’ slash-separated path segments, each as a percent-encoded ASCII string.

Return None for cannot-be-a-base URLs.

When Some is returned, the iterator always contains at least one string (which may be empty).

§Examples
use url::Url;


let url = Url::parse("https://example.com/foo/bar")?;
let mut path_segments = url.path_segments().ok_or_else(|| "cannot be base")?;
assert_eq!(path_segments.next(), Some("foo"));
assert_eq!(path_segments.next(), Some("bar"));
assert_eq!(path_segments.next(), None);

let url = Url::parse("https://example.com")?;
let mut path_segments = url.path_segments().ok_or_else(|| "cannot be base")?;
assert_eq!(path_segments.next(), Some(""));
assert_eq!(path_segments.next(), None);

let url = Url::parse("data:text/plain,HelloWorld")?;
assert!(url.path_segments().is_none());

let url = Url::parse("https://example.com/countries/việt nam")?;
let mut path_segments = url.path_segments().ok_or_else(|| "cannot be base")?;
assert_eq!(path_segments.next(), Some("countries"));
assert_eq!(path_segments.next(), Some("vi%E1%BB%87t%20nam"));
Source

pub fn query(&self) -> Option<&str>

Return this URL’s query string, if any, as a percent-encoded ASCII string.

§Examples
use url::Url;

fn run() -> Result<(), ParseError> {
let url = Url::parse("https://example.com/products?page=2")?;
let query = url.query();
assert_eq!(query, Some("page=2"));

let url = Url::parse("https://example.com/products")?;
let query = url.query();
assert!(query.is_none());

let url = Url::parse("https://example.com/?country=español")?;
let query = url.query();
assert_eq!(query, Some("country=espa%C3%B1ol"));
Source

pub fn query_pairs(&self) -> Parse<'_>

Parse the URL’s query string, if any, as application/x-www-form-urlencoded and return an iterator of (key, value) pairs.

§Examples
use std::borrow::Cow;

use url::Url;

let url = Url::parse("https://example.com/products?page=2&sort=desc")?;
let mut pairs = url.query_pairs();

assert_eq!(pairs.count(), 2);

assert_eq!(pairs.next(), Some((Cow::Borrowed("page"), Cow::Borrowed("2"))));
assert_eq!(pairs.next(), Some((Cow::Borrowed("sort"), Cow::Borrowed("desc"))));
Source

pub fn fragment(&self) -> Option<&str>

Return this URL’s fragment identifier, if any.

A fragment is the part of the URL after the # symbol. The fragment is optional and, if present, contains a fragment identifier that identifies a secondary resource, such as a section heading of a document.

In HTML, the fragment identifier is usually the id attribute of a an element that is scrolled to on load. Browsers typically will not send the fragment portion of a URL to the server.

Note: the parser did not percent-encode this component, but the input may have been percent-encoded already.

§Examples
use url::Url;

let url = Url::parse("https://example.com/data.csv#row=4")?;

assert_eq!(url.fragment(), Some("row=4"));

let url = Url::parse("https://example.com/data.csv#cell=4,1-6,2")?;

assert_eq!(url.fragment(), Some("cell=4,1-6,2"));
Source

pub fn serialize_internal<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize with Serde using the internal representation of the Url struct.

The corresponding deserialize_internal method sacrifices some invariant-checking for speed, compared to the Deserialize trait impl.

This method is only available if the serde Cargo feature is enabled.

Source

pub fn to_file_path(&self) -> Result<PathBuf, ()>

Assuming the URL is in the file scheme or similar, convert its path to an absolute std::path::Path.

Note: This does not actually check the URL’s scheme, and may give nonsensical results for other schemes. It is the user’s responsibility to check the URL’s scheme before calling this.

let path = url.to_file_path();

Returns Err if the host is neither empty nor "localhost" (except on Windows, where file: URLs may have a non-local host), or if Path::new_opt() returns None. (That is, if the percent-decoded path contains a NUL byte or, for a Windows path, is not UTF-8.)

This method is only available if the std Cargo feature is enabled.

Trait Implementations§

Source§

impl AsRef<Url> for BetterUrl

Source§

fn as_ref(&self) -> &Url

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<str> for BetterUrl

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for BetterUrl

Source§

fn clone(&self) -> BetterUrl

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BetterUrl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Deref for BetterUrl

Source§

type Target = Url

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<BetterUrl as Deref>::Target

Dereferences the value.
Source§

impl<'de> Deserialize<'de> for BetterUrl

Source§

fn deserialize<D>( deserializer: D, ) -> Result<BetterUrl, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for BetterUrl

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<BetterUrl> for LazyTaskConfig<'_>

Source§

fn from(value: BetterUrl) -> Self

Converts to this type from the input type.
Source§

impl From<BetterUrl> for TaskConfig

Source§

fn from(value: BetterUrl) -> Self

Defaults Self::context.

Source§

impl From<BetterUrl> for Url

Source§

fn from(value: BetterUrl) -> Url

Converts to this type from the input type.
Source§

impl From<Url> for BetterUrl

Source§

fn from(value: Url) -> BetterUrl

Converts to this type from the input type.
Source§

impl FromStr for BetterUrl

Source§

type Err = <Url as FromStr>::Err

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<BetterUrl, <BetterUrl as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for BetterUrl

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Hashes the same as Url.

1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for BetterUrl

Source§

fn cmp(&self, other: &BetterUrl) -> Ordering

Ordered the same as Url.

1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq<&str> for BetterUrl

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<BetterUrl> for &str

Source§

fn eq(&self, other: &BetterUrl) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<BetterUrl> for Url

Source§

fn eq(&self, other: &BetterUrl) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<BetterUrl> for str

Source§

fn eq(&self, other: &BetterUrl) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<String> for BetterUrl

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Url> for BetterUrl

Source§

fn eq(&self, other: &Url) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for BetterUrl

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for BetterUrl

Source§

fn eq(&self, other: &BetterUrl) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for BetterUrl

Source§

fn partial_cmp(&self, other: &BetterUrl) -> Option<Ordering>

Ordered the same as Url.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for BetterUrl

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&str> for BetterUrl

Source§

type Error = <BetterUrl as FromStr>::Err

The type returned in the event of a conversion error.
Source§

fn try_from( value: &str, ) -> Result<BetterUrl, <BetterUrl as TryFrom<&str>>::Error>

Performs the conversion.
Source§

impl Eq for BetterUrl

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,