pub struct Name<'a> { /* private fields */ }
Expand description
A Name represents a domain-name, which consists of character strings separated by dots.
Each section of a name is called label
ex: google.com
consists of two labels google
and com
A valid name contains only alphanumeric characters, hyphen (-), underscore (_) or dots (.) and must not exceed 255 characters. Each label must not exceed 63 characters.
Microsoft implementation allows unicode characters in the name content.
To create a name with unicode characters, use Name::new_unchecked
or
Name::new_with_labels
Implementations§
source§impl<'a> Name<'a>
impl<'a> Name<'a>
sourcepub fn new(name: &'a str) -> Result<Self>
pub fn new(name: &'a str) -> Result<Self>
Creates a new Name. Returns Result::<Name>::Ok
if given name
contents are valid.
sourcepub fn new_unchecked(name: &'a str) -> Self
pub fn new_unchecked(name: &'a str) -> Self
Create a new Name without checking for size limits or contents
sourcepub fn new_with_labels(labels: &[Label<'a>]) -> Self
pub fn new_with_labels(labels: &[Label<'a>]) -> Self
Creates a new Name with given labels
Allows construction of labels with .
in them.
sourcepub fn is_link_local(&self) -> bool
pub fn is_link_local(&self) -> bool
Verify if name ends with .local.
sourcepub fn is_subdomain_of(&self, other: &Name<'_>) -> bool
pub fn is_subdomain_of(&self, other: &Name<'_>) -> bool
Returns true if self is a subdomain of other
sourcepub fn without(&self, domain: &Name<'_>) -> Option<Name<'_>>
pub fn without(&self, domain: &Name<'_>) -> Option<Name<'_>>
Returns the subdomain part of self, based on domain
.
If self is not a subdomain of domain
, returns None
Example:
let name = Name::new_unchecked("sub.domain.local");
let domain = Name::new_unchecked("domain.local");
assert!(domain.without(&name).is_none());
let sub = name.without(&domain).unwrap();
assert_eq!(sub.to_string(), "sub")
sourcepub fn into_owned<'b>(self) -> Name<'b>
pub fn into_owned<'b>(self) -> Name<'b>
Transforms the inner data into its owned type
sourcepub fn get_labels(&self) -> &[Label<'_>]
pub fn get_labels(&self) -> &[Label<'_>]
Get the labels that compose this name
Trait Implementations§
impl<'a> Eq for Name<'a>
Auto Trait Implementations§
impl<'a> Freeze for Name<'a>
impl<'a> RefUnwindSafe for Name<'a>
impl<'a> Send for Name<'a>
impl<'a> Sync for Name<'a>
impl<'a> Unpin for Name<'a>
impl<'a> UnwindSafe for Name<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)