use bytes::Bytes;
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct ServerName(Bytes);
#[allow(dead_code)] pub(crate) static LOCALHOST: ServerName = ServerName::from_static("localhost");
impl ServerName {
#[inline]
pub fn into_bytes(self) -> Bytes {
self.0
}
pub const fn from_static(s: &'static str) -> Self {
ServerName(Bytes::from_static(s.as_bytes()))
}
#[inline]
fn as_str(&self) -> &str {
unsafe { core::str::from_utf8_unchecked(&self.0) }
}
}
impl From<&str> for ServerName {
#[inline]
fn from(data: &str) -> Self {
Self(Bytes::copy_from_slice(data.as_bytes()))
}
}
#[cfg(feature = "alloc")]
impl From<alloc::string::String> for ServerName {
#[inline]
fn from(data: alloc::string::String) -> Self {
Self(data.into_bytes().into())
}
}
impl core::fmt::Debug for ServerName {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
self.as_str().fmt(f)
}
}
impl core::ops::Deref for ServerName {
type Target = str;
#[inline]
fn deref(&self) -> &Self::Target {
self.as_str()
}
}