use crate::prelude::*;
#[cfg(feature = "psl")]
mod prefix;
#[cfg(feature = "psl")]
mod middle;
#[cfg(feature = "psl")]
mod suffix;
mod fqddot;
mod labels;
#[cfg(feature = "psl")]
mod origin;
#[cfg(feature = "psl")]
mod normal;
impl BetterUrl {
pub fn has_domain(&self) -> bool {
self.domain_details().is_some()
}
pub fn domain_str(&self) -> Option<&str> {
(self.details.host_type() == Some(HostType::Domain)).then_some(self.host_str()?)
}
pub fn domain_segment_strs(&self) -> Option<SplitDots<'_>> {
self.domain_labels_segment_strs()
}
pub fn domain_segment_str(&self, index: isize) -> Option<&str> {
self.domain_labels_segment_str(index)
}
pub fn domain_range_str<B: RangeBounds<isize>>(&self, range: B) -> Option<&str> {
self.domain_labels_range_str(range)
}
pub fn domain(&self) -> Option<DomainHost<'_>> {
Some(unsafe {DomainHost::from_parts(self.host_str()?, self.domain_details()?)})
}
pub fn domain_segments(&self) -> Option<DomainSegmentsIter<'_>> {
self.domain_labels_segments()
}
pub fn domain_segment(&self, index: isize) -> Option<DomainSegment<'_>> {
self.domain_labels_segment(index)
}
pub fn domain_range<B: RangeBounds<isize>>(&self, range: B) -> Option<DomainSegments<'_>> {
self.domain_labels_range(range)
}
pub fn set_domain_segment<'b, T: TryInto<DomainSegment<'b>>>(&mut self, index: isize, value: Option<T>) -> Result<bool, SetHostError> where SetDomainError: From<T::Error> {
let mut domain = self.domain().ok_or(NoDomain)?;
if domain.set_segment(index, value)? {
self.set_host(domain.into_owned())?;
Ok(true)
} else {
Ok(false)
}
}
pub fn insert_domain_segment<'b, T: TryInto<DomainSegment<'b>>>(&mut self, index: isize, value: T) -> Result<(), SetHostError> where SetDomainError: From<T::Error> {
let mut domain = self.domain().ok_or(NoDomain)?;
domain.insert_segment(index, value)?;
self.set_host(domain.into_owned())?;
Ok(())
}
pub fn set_domain_range<'b, T: TryInto<DomainSegments<'b>>, B: RangeBounds<isize>>(&mut self, range: B, value: Option<T>) -> Result<bool, SetHostError> where SetDomainError: From<T::Error> {
let mut domain = self.domain().ok_or(NoDomain)?;
if domain.set_range(range, value)? {
self.set_host(domain.into_owned())?;
Ok(true)
} else {
Ok(false)
}
}
}