1#![warn(missing_docs)]
20
21use avila_error::{Error, ErrorKind, Result};
22use tokio::net::{TcpListener, TcpStream, UdpSocket};
23use tokio::io::{AsyncReadExt, AsyncWriteExt};
24
25pub mod tcp;
26pub mod udp;
27pub mod tls;
28
29pub const VERSION: &str = env!("CARGO_PKG_VERSION");
31
32#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct NetworkAddress {
35 pub host: String,
37 pub port: u16,
39}
40
41impl NetworkAddress {
42 pub fn new(host: impl Into<String>, port: u16) -> Self {
44 Self {
45 host: host.into(),
46 port,
47 }
48 }
49
50 pub fn to_string(&self) -> String {
52 format!("{}:{}", self.host, self.port)
53 }
54}
55
56impl std::fmt::Display for NetworkAddress {
57 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58 write!(f, "{}:{}", self.host, self.port)
59 }
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn test_network_address() {
68 let addr = NetworkAddress::new("localhost", 8080);
69 assert_eq!(addr.to_string(), "localhost:8080");
70 }
71}