pub struct Hostname<'a> { /* private fields */ }
Expand description
A validated hostname.
This is not used within this crate, it is provided here for crates implementing protocols such as DNS and DHCP to use.
Implementations§
source§impl<'a> Hostname<'a>
impl<'a> Hostname<'a>
sourcepub const fn new(hostname: &'a str) -> Option<Self>
pub const fn new(hostname: &'a str) -> Option<Self>
Create a new hostname.
This validates the hostname for RFC-1035 compliance:
A hostname is valid if the following condition are true:
- It does not start or end with
'-'
or'.'
. - It does not contain any characters outside of the alphanumeric range, except for
'-'
and'.'
. - It is not empty.
- It is 253 or fewer characters.
- Its labels (characters separated by
.
) are not empty. - Its labels are 63 or fewer characters.
- Its labels do not start or end with
'-'
or'.'
.
Example
use w5500_hl::Hostname;
assert!(Hostname::new("is-valid-example").is_some());
assert!(Hostname::new("this-is-not-?-valid").is_none());
sourcepub const fn new_unwrapped(hostname: &'a str) -> Self
pub const fn new_unwrapped(hostname: &'a str) -> Self
Create a new hostname, panicking if the hostname is invalid.
Panics
This is the same as new
, but it will panic on invalid
hostnames.
This should only be used in const
contexts where the evaluation will
fail at compile time.
Example
use w5500_hl::Hostname;
const MY_HOSTNAME: Hostname = Hostname::new_unwrapped("valid.hostname");
sourcepub fn labels(&self) -> Split<'a, char>
pub fn labels(&self) -> Split<'a, char>
Returns an iterator over the labels of the hostname.
Example
use core::str::Split;
use w5500_hl::Hostname;
const DOCS_RS: Hostname = Hostname::new_unwrapped("docs.rs");
let mut lables: Split<char> = DOCS_RS.labels();
assert_eq!(lables.next(), Some("docs"));
assert_eq!(lables.next(), Some("rs"));
assert_eq!(lables.next(), None);
sourcepub fn len(&self) -> u8
pub fn len(&self) -> u8
Length of the hostname in bytes.
Example
use w5500_hl::Hostname;
const DOCS_RS: Hostname = Hostname::new_unwrapped("docs.rs");
assert_eq!(DOCS_RS.len(), 7);
sourcepub const unsafe fn new_unchecked(hostname: &'a str) -> Self
pub const unsafe fn new_unchecked(hostname: &'a str) -> Self
Trait Implementations§
impl<'a> Copy for Hostname<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for Hostname<'a>
impl<'a> Send for Hostname<'a>
impl<'a> Sync for Hostname<'a>
impl<'a> Unpin for Hostname<'a>
impl<'a> UnwindSafe for Hostname<'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
Mutably borrows from an owned value. Read more