mod sync;
mod time;
#[cfg(feature = "tokio")]
mod tokio;
#[cfg(feature = "tokio")]
pub use self::tokio::*;
pub use sync::*;
pub use time::*;
use crate::string::{Builder, Word};
const BUFSIZE: usize = 16384;
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde_derive::Serialize, serde_derive::Deserialize))]
pub struct ServerAddr<'a> {
pub address: Word<'a>,
pub tls: bool,
pub port: Option<u16>,
}
impl<'a> PartialEq for ServerAddr<'a> {
fn eq(&self, other: &Self) -> bool {
self.tls == other.tls
&& self.port_num() == other.port_num()
&& self.address == other.address
}
}
impl<'a> Eq for ServerAddr<'a> {}
impl<'a> std::hash::Hash for ServerAddr<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
state.write(self.address.as_bytes());
state.write_u8(self.tls as u8);
state.write_u16(self.port_num());
}
}
impl<'a> ServerAddr<'a> {
fn utf8_address(&self) -> std::io::Result<&str> {
self.address.to_utf8().ok_or_else(|| {
std::io::Error::new(std::io::ErrorKind::InvalidInput, "non-utf8 address")
})
}
pub fn from_host<A: TryInto<Word<'a>>>(address: A) -> Result<Self, A::Error> {
let address = address.try_into()?;
Ok(Self { address, tls: true, port: None })
}
pub const fn from_host_str(address: &'a str) -> Self {
let address = Word::from_str(address);
Self { address, tls: true, port: None }
}
pub fn to_word(&self) -> Word<'static> {
let mut builder = Builder::<Word<'static>>::default();
builder.reserve_exact(self.address.len() + 9);
builder.append(self.address.clone());
if self.tls {
builder.append(crate::names::PLUS);
}
unsafe {
builder.append_unchecked(self.port_num().to_string(), true);
}
builder.build()
}
pub const fn port_num(&self) -> u16 {
if let Some(no) = self.port {
no
} else if self.tls {
6697
} else {
6667
}
}
}
#[derive(Clone, Debug, Default)]
pub struct Bidir<R, W>(pub R, pub W);