Struct fqdn::Fqdn [−][src]
pub struct Fqdn(_);Expand description
Implementations
Checks if this is the top domain.
The human-readable representation of the top domain is the single dot ..
Checks if this domain is an descendant of another one.
Example
assert![ fqdn!("github.com.").is_subdomain_of(&fqdn!("github.com.")) ];
assert![ fqdn!("www.rust-lang.github.com").is_subdomain_of(&fqdn!("github.com.")) ];
assert![ ! fqdn!("github.com.").is_subdomain_of(&fqdn!("www.rust-lang.github.com")) ];Gets the top level domain.
The TLD is the last part of a FQDN.
For instance, the TLD of rust-lang.github.io. is io.
If the FQDN is already a TLD, self is returned.
If the FQDN is the top domain, None is returned.
Example
assert_eq![ fqdn!("rust-lang.github.com.").tld(), Some(fqdn!("com.").as_ref()) ];
assert_eq![ fqdn!(".").tld(), None ];Extracts a Fqdn slice with contains the immediate parent domain.
The parent is the domain after remaining the first label.
If it is already the top domain, then None is returned.
To iterate over the hierarchy of a FQDN, consider Self::hierarchy
Example
assert_eq![ fqdn!("github.com").parent(), Some(fqdn!("com").as_ref()) ];
assert_eq![ fqdn!("github.com").parent().unwrap().parent(), None ];
assert_eq![ fqdn!(".").parent(), None ];Iterates over the parents of the FQDN.
Example
let fqdn = fqdn!("rust-lang.github.com.");
let mut iter = fqdn.hierarchy();
assert_eq![ iter.next(), Some(fqdn!("rust-lang.github.com.").as_ref()) ];
assert_eq![ iter.next(), Some(fqdn!("github.com.").as_ref()) ];
assert_eq![ iter.next(), Some(fqdn!("com.").as_ref()) ];
assert_eq![ iter.next(), None ];Computes the depth of this domain (i.e. counts the labels)
Example
assert_eq![ fqdn!("rust-lang.github.com.").depth(), 3 ];
assert_eq![ fqdn!("github.com.").depth(), 2 ];
assert_eq![ fqdn!(".").depth(), 0 ];Builds a FQDN from a byte sequence.
If the byte sequence does not follow the rules, an error is produced.
See Error for more details on errors.
If one is sure that the sequence matches all the rules, then the unchecking version
Self::from_bytes_unchecked could be use to be more efficient.
Example
assert_eq![ Fqdn::from_bytes(b"\x06crates\x02io\x00"), Ok(fqdn!("crates.io.").as_ref()) ];
assert_eq![ Fqdn::from_bytes(b"\x06crates\x02io"), Err(Error::TrailingNulCharMissing) ];
assert_eq![ Fqdn::from_bytes(b"\x06cr@tes\x02io\x00"), Err(Error::InvalidLabelChar) ];
assert_eq![ Fqdn::from_bytes(b"\x02crates\x02io\x00"), Err(Error::InvalidStructure) ];Builds without any check a FQDN from a byte sequence.
Safety
This function is unsafe because it does not check that the bytes passed to it are valid and are well-structured. It means that:
- each label starts with a byte indicating its length
- the bytes sequence ends with a nul-byte
- only allowed ASCII characters are present in labels
- the size limits should be respected
If one of these constraints is violated, it may cause memory unsafety issues with future users of the FQDN.
Consider Self::from_bytes for a safe version of this function.
Example
let crates = unsafe {
Fqdn::from_bytes_unchecked(b"\x06crates\x02io\x00")
};
assert_eq![ *crates, fqdn!("crates.io.") ];Returns the complete byte sequence of the FQDN.
The returned sequence is terminated by the nul byte.
Example
assert_eq![ fqdn!("crates.io.").as_bytes(), b"\x06crates\x02io\x00" ];Iterates over the labels which constitutes the FQDN.
Example
let fqdn = fqdn!("rust-lang.github.com.");
let mut iter = fqdn.labels();
assert_eq![ iter.next(), Some("rust-lang") ];
assert_eq![ iter.next(), Some("github") ];
assert_eq![ iter.next(), Some("com") ];
assert_eq![ iter.next(), None ];Trait Implementations
🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more