#unix-domain-socket #address #networking

socket-address

一个简单的套接字地址实现,可以是网络套接字或 Unix 域套接字

2 个不稳定版本

0.2.0 2023年11月5日
0.1.0 2023年7月26日

20#unix-domain-socket

Download history 36/week @ 2024-03-13 35/week @ 2024-03-20 29/week @ 2024-03-27 25/week @ 2024-04-03 8/week @ 2024-04-10 6/week @ 2024-04-17 39/week @ 2024-04-24 35/week @ 2024-05-01 77/week @ 2024-05-08 51/week @ 2024-05-15 38/week @ 2024-05-22 49/week @ 2024-05-29 38/week @ 2024-06-05 80/week @ 2024-06-12 36/week @ 2024-06-19 108/week @ 2024-06-26

263 每月下载量

MIT 许可证

6KB
81 代码行

ListenAddress

use core::str::FromStr;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

use socket_address::ListenAddress;

let addr = ListenAddress::from_str("0.0.0.0:80").unwrap();
assert_eq!(addr, ListenAddress::Network(SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 80)));
use core::str::FromStr;
use std::path::PathBuf;

use socket_address::ListenAddress;

let addr = ListenAddress::from_str("unix:myapp.sock").unwrap();
assert_eq!(addr, ListenAddress::UnixSocket("myapp.sock".into()));

ConnectAddress

use core::str::FromStr;
use http::Uri;

use socket_address::ConnectAddress;

let addr = ConnectAddress::from_str("http://127.0.0.1/").unwrap();
assert_eq!(addr, ConnectAddress::Uri(Uri::from_str("http://127.0.0.1/").unwrap()));
use core::str::FromStr;
use std::path::PathBuf;

use socket_address::ConnectAddress;

let addr = ConnectAddress::from_str("unix:myapp.sock").unwrap();
assert_eq!(addr, ConnectAddress::UnixSocket("myapp.sock".into()));

依赖项

~0.8–1.3MB
~27K SLoC