pub struct DomainDetails {
pub middle_start: Option<usize>,
pub suffix_start: Option<usize>,
pub fqdn_period: Option<usize>,
}Expand description
The details of a domain host.
Fields§
§middle_start: Option<usize>The start of the domain middle.
suffix_start: Option<usize>The start of the domain suffix.
fqdn_period: Option<usize>The location of the fully qualified domain name period.
Implementations§
Source§impl DomainDetails
impl DomainDetails
Sourcepub fn parse(domain: &str) -> Result<DomainDetails, GetDomainDetailsError>
pub fn parse(domain: &str) -> Result<DomainDetails, GetDomainDetailsError>
Checks if domain is a valid domain, then returns its details.
If you’re absolutely certain the value you’re using is a valid domain, you can use Self::parse_unchecked.
§Errors
If the call to url::Host::parse returns an error, that error is returned.
If the call to url::Host::parse doesn’t return url::Host::Domain, returns the error GetDomainDetailsError::NotADomain.
§Examples
use better_url::*;
assert_eq!(DomainDetails::parse( "example.com" ).unwrap(), DomainDetails {middle_start: Some(0), suffix_start: Some( 8), fqdn_period: None});
assert_eq!(DomainDetails::parse("www.example.com" ).unwrap(), DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: None});
assert_eq!(DomainDetails::parse( "example.co.uk" ).unwrap(), DomainDetails {middle_start: Some(0), suffix_start: Some( 8), fqdn_period: None});
assert_eq!(DomainDetails::parse("www.example.co.uk" ).unwrap(), DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: None});
assert_eq!(DomainDetails::parse( "example.com." ).unwrap(), DomainDetails {middle_start: Some(0), suffix_start: Some( 8), fqdn_period: Some(11)});
assert_eq!(DomainDetails::parse("www.example.com." ).unwrap(), DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: Some(15)});
assert_eq!(DomainDetails::parse( "example.co.uk.").unwrap(), DomainDetails {middle_start: Some(0), suffix_start: Some( 8), fqdn_period: Some(13)});
assert_eq!(DomainDetails::parse("www.example.co.uk.").unwrap(), DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: Some(17)});
DomainDetails::parse("127.0.0.1").unwrap_err();
DomainDetails::parse("[::1]").unwrap_err();Sourcepub fn parse_unchecked(domain: &str) -> DomainDetails
pub fn parse_unchecked(domain: &str) -> DomainDetails
Gets the details of a domain without checking it’s actually a domain first.
If you are at all possibly not working with a domain (like an IP host), please use Self::parse instead.
§Examples
use better_url::*;
assert_eq!(DomainDetails::parse_unchecked( "example.com" ), DomainDetails {middle_start: Some(0), suffix_start: Some( 8), fqdn_period: None});
assert_eq!(DomainDetails::parse_unchecked("www.example.com" ), DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: None});
assert_eq!(DomainDetails::parse_unchecked( "example.co.uk" ), DomainDetails {middle_start: Some(0), suffix_start: Some( 8), fqdn_period: None});
assert_eq!(DomainDetails::parse_unchecked("www.example.co.uk" ), DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: None});
assert_eq!(DomainDetails::parse_unchecked( "example.com." ), DomainDetails {middle_start: Some(0), suffix_start: Some( 8), fqdn_period: Some(11)});
assert_eq!(DomainDetails::parse_unchecked("www.example.com." ), DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: Some(15)});
assert_eq!(DomainDetails::parse_unchecked( "example.co.uk."), DomainDetails {middle_start: Some(0), suffix_start: Some( 8), fqdn_period: Some(13)});
assert_eq!(DomainDetails::parse_unchecked("www.example.co.uk."), DomainDetails {middle_start: Some(4), suffix_start: Some(12), fqdn_period: Some(17)});Sourcepub fn subdomain_period(&self) -> Option<usize>
pub fn subdomain_period(&self) -> Option<usize>
The location of the period between subdomain and domain middle.
§Examples
use better_url::*;
assert_eq!(DomainDetails::parse( "example.com" ).unwrap().subdomain_period(), None );
assert_eq!(DomainDetails::parse("www.example.com" ).unwrap().subdomain_period(), Some(3));
assert_eq!(DomainDetails::parse( "example.co.uk" ).unwrap().subdomain_period(), None );
assert_eq!(DomainDetails::parse("www.example.co.uk" ).unwrap().subdomain_period(), Some(3));
assert_eq!(DomainDetails::parse( "example.com." ).unwrap().subdomain_period(), None );
assert_eq!(DomainDetails::parse("www.example.com." ).unwrap().subdomain_period(), Some(3));
assert_eq!(DomainDetails::parse( "example.co.uk.").unwrap().subdomain_period(), None );
assert_eq!(DomainDetails::parse("www.example.co.uk.").unwrap().subdomain_period(), Some(3));Sourcepub fn domain_suffix_period(&self) -> Option<usize>
pub fn domain_suffix_period(&self) -> Option<usize>
The location of the period between domain middle and domain suffix.
§Examples
use better_url::*;
assert_eq!(DomainDetails::parse( "example.com" ).unwrap().domain_suffix_period(), Some( 7));
assert_eq!(DomainDetails::parse("www.example.com" ).unwrap().domain_suffix_period(), Some(11));
assert_eq!(DomainDetails::parse( "example.co.uk" ).unwrap().domain_suffix_period(), Some( 7));
assert_eq!(DomainDetails::parse("www.example.co.uk" ).unwrap().domain_suffix_period(), Some(11));
assert_eq!(DomainDetails::parse( "example.com." ).unwrap().domain_suffix_period(), Some( 7));
assert_eq!(DomainDetails::parse("www.example.com." ).unwrap().domain_suffix_period(), Some(11));
assert_eq!(DomainDetails::parse( "example.co.uk.").unwrap().domain_suffix_period(), Some( 7));
assert_eq!(DomainDetails::parse("www.example.co.uk.").unwrap().domain_suffix_period(), Some(11));Sourcepub fn domain_bounds(&self) -> (Bound<usize>, Bound<usize>)
pub fn domain_bounds(&self) -> (Bound<usize>, Bound<usize>)
The bounds of domain.
Notably does not include Self::fqdn_period
§Examples
use better_url::*;
let x = "example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_bounds()], "example.com" );
let x = "www.example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_bounds()], "www.example.com" );
let x = "example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_bounds()], "example.co.uk");
let x = "www.example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_bounds()], "www.example.co.uk");
let x = "example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_bounds()], "example.com" );
let x = "www.example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_bounds()], "www.example.com" );
let x = "example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_bounds()], "example.co.uk");
let x = "www.example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_bounds()], "www.example.co.uk");Sourcepub fn subdomain_bounds(&self) -> Option<(Bound<usize>, Bound<usize>)>
pub fn subdomain_bounds(&self) -> Option<(Bound<usize>, Bound<usize>)>
The bounds of subdomain.
§Examples
use better_url::*;
let x = "example.com" ; assert_eq!( DomainDetails::parse(x).unwrap().subdomain_bounds() , None );
let x = "www.example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().subdomain_bounds().unwrap()], "www");
let x = "example.co.uk" ; assert_eq!( DomainDetails::parse(x).unwrap().subdomain_bounds() , None );
let x = "www.example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().subdomain_bounds().unwrap()], "www");
let x = "example.com." ; assert_eq!( DomainDetails::parse(x).unwrap().subdomain_bounds() , None );
let x = "www.example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().subdomain_bounds().unwrap()], "www");
let x = "example.co.uk."; assert_eq!( DomainDetails::parse(x).unwrap().subdomain_bounds() , None );
let x = "www.example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().subdomain_bounds().unwrap()], "www");Sourcepub fn not_domain_suffix_bounds(&self) -> Option<(Bound<usize>, Bound<usize>)>
pub fn not_domain_suffix_bounds(&self) -> Option<(Bound<usize>, Bound<usize>)>
The bounds of not domain suffix.
§Examples
use better_url::*;
let x = "example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().not_domain_suffix_bounds().unwrap()], "example");
let x = "www.example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().not_domain_suffix_bounds().unwrap()], "www.example");
let x = "example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().not_domain_suffix_bounds().unwrap()], "example");
let x = "www.example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().not_domain_suffix_bounds().unwrap()], "www.example");
let x = "example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().not_domain_suffix_bounds().unwrap()], "example");
let x = "www.example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().not_domain_suffix_bounds().unwrap()], "www.example");
let x = "example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().not_domain_suffix_bounds().unwrap()], "example");
let x = "www.example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().not_domain_suffix_bounds().unwrap()], "www.example");Sourcepub fn domain_middle_bounds(&self) -> Option<(Bound<usize>, Bound<usize>)>
pub fn domain_middle_bounds(&self) -> Option<(Bound<usize>, Bound<usize>)>
The bounds of domain middle.
§Examples
use better_url::*;
let x = "example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_middle_bounds().unwrap()], "example");
let x = "www.example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_middle_bounds().unwrap()], "example");
let x = "example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_middle_bounds().unwrap()], "example");
let x = "www.example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_middle_bounds().unwrap()], "example");
let x = "example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_middle_bounds().unwrap()], "example");
let x = "www.example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_middle_bounds().unwrap()], "example");
let x = "example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_middle_bounds().unwrap()], "example");
let x = "www.example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_middle_bounds().unwrap()], "example");Sourcepub fn reg_domain_bounds(&self) -> Option<(Bound<usize>, Bound<usize>)>
pub fn reg_domain_bounds(&self) -> Option<(Bound<usize>, Bound<usize>)>
The bounds of reg domain.
Notably does not include Self::fqdn_period
§Examples
use better_url::*;
let x = "example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().reg_domain_bounds().unwrap()], "example.com" );
let x = "www.example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().reg_domain_bounds().unwrap()], "example.com" );
let x = "example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().reg_domain_bounds().unwrap()], "example.co.uk");
let x = "www.example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().reg_domain_bounds().unwrap()], "example.co.uk");
let x = "example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().reg_domain_bounds().unwrap()], "example.com" );
let x = "www.example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().reg_domain_bounds().unwrap()], "example.com" );
let x = "example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().reg_domain_bounds().unwrap()], "example.co.uk");
let x = "www.example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().reg_domain_bounds().unwrap()], "example.co.uk");Sourcepub fn domain_suffix_bounds(&self) -> Option<(Bound<usize>, Bound<usize>)>
pub fn domain_suffix_bounds(&self) -> Option<(Bound<usize>, Bound<usize>)>
The bounds of domain suffix.
Notably does not include Self::fqdn_period
§Examples
use better_url::*;
let x = "example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_suffix_bounds().unwrap()], "com" );
let x = "www.example.com" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_suffix_bounds().unwrap()], "com" );
let x = "example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_suffix_bounds().unwrap()], "co.uk");
let x = "www.example.co.uk" ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_suffix_bounds().unwrap()], "co.uk");
let x = "example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_suffix_bounds().unwrap()], "com" );
let x = "www.example.com." ; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_suffix_bounds().unwrap()], "com" );
let x = "example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_suffix_bounds().unwrap()], "co.uk");
let x = "www.example.co.uk."; assert_eq!(&x[DomainDetails::parse(x).unwrap().domain_suffix_bounds().unwrap()], "co.uk");Sourcepub fn is_fqdn(&self) -> bool
pub fn is_fqdn(&self) -> bool
If Self describes a fully qualified domain name, return true.
§Examples
use better_url::*;
assert!(!DomainDetails::parse( "example.com" ).unwrap().is_fqdn());
assert!(!DomainDetails::parse("www.example.com" ).unwrap().is_fqdn());
assert!(!DomainDetails::parse( "example.co.uk" ).unwrap().is_fqdn());
assert!(!DomainDetails::parse("www.example.co.uk" ).unwrap().is_fqdn());
assert!( DomainDetails::parse( "example.com." ).unwrap().is_fqdn());
assert!( DomainDetails::parse("www.example.com." ).unwrap().is_fqdn());
assert!( DomainDetails::parse( "example.co.uk.").unwrap().is_fqdn());
assert!( DomainDetails::parse("www.example.co.uk.").unwrap().is_fqdn());Trait Implementations§
Source§impl Clone for DomainDetails
impl Clone for DomainDetails
Source§fn clone(&self) -> DomainDetails
fn clone(&self) -> DomainDetails
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DomainDetails
impl Debug for DomainDetails
Source§impl<'de> Deserialize<'de> for DomainDetails
impl<'de> Deserialize<'de> for DomainDetails
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<DomainDetails, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<DomainDetails, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<DomainDetails> for HostDetails
impl From<DomainDetails> for HostDetails
Source§fn from(value: DomainDetails) -> HostDetails
fn from(value: DomainDetails) -> HostDetails
Source§impl FromStr for DomainDetails
impl FromStr for DomainDetails
Source§type Err = GetDomainDetailsError
type Err = GetDomainDetailsError
Source§fn from_str(s: &str) -> Result<DomainDetails, <DomainDetails as FromStr>::Err>
fn from_str(s: &str) -> Result<DomainDetails, <DomainDetails as FromStr>::Err>
s to return a value of this type. Read moreSource§impl PartialEq for DomainDetails
impl PartialEq for DomainDetails
Source§impl Serialize for DomainDetails
impl Serialize for DomainDetails
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl TryFrom<HostDetails> for DomainDetails
impl TryFrom<HostDetails> for DomainDetails
Source§type Error = HostIsNotDomain
type Error = HostIsNotDomain
Source§fn try_from(
value: HostDetails,
) -> Result<DomainDetails, <DomainDetails as TryFrom<HostDetails>>::Error>
fn try_from( value: HostDetails, ) -> Result<DomainDetails, <DomainDetails as TryFrom<HostDetails>>::Error>
impl Copy for DomainDetails
impl Eq for DomainDetails
impl StructuralPartialEq for DomainDetails
Auto Trait Implementations§
impl Freeze for DomainDetails
impl RefUnwindSafe for DomainDetails
impl Send for DomainDetails
impl Sync for DomainDetails
impl Unpin for DomainDetails
impl UnwindSafe for DomainDetails
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more