#![warn(missing_docs)]
use avila_error::{Error, ErrorKind, Result};
use tokio::net::{TcpListener, TcpStream, UdpSocket};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
pub mod tcp;
pub mod udp;
pub mod tls;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NetworkAddress {
pub host: String,
pub port: u16,
}
impl NetworkAddress {
pub fn new(host: impl Into<String>, port: u16) -> Self {
Self {
host: host.into(),
port,
}
}
pub fn to_string(&self) -> String {
format!("{}:{}", self.host, self.port)
}
}
impl std::fmt::Display for NetworkAddress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}", self.host, self.port)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_network_address() {
let addr = NetworkAddress::new("localhost", 8080);
assert_eq!(addr.to_string(), "localhost:8080");
}
}