#unix-domain-socket #sockets #unix-socket #address #networking

socket-address

A simple implementation of a socket address that can be either a network socket or a Unix domain socket

3 releases (breaking)

0.3.0 Oct 1, 2024
0.2.0 Nov 5, 2023
0.1.0 Jul 26, 2023

#1196 in Network programming

Download history 3/week @ 2024-09-07 99/week @ 2024-09-14 78/week @ 2024-09-21 299/week @ 2024-09-28 54/week @ 2024-10-05 40/week @ 2024-10-12 30/week @ 2024-10-19 64/week @ 2024-10-26 31/week @ 2024-11-02 37/week @ 2024-11-09 25/week @ 2024-11-16 53/week @ 2024-11-23 83/week @ 2024-11-30 131/week @ 2024-12-07 5/week @ 2024-12-14 17/week @ 2024-12-21

237 downloads per month

MIT license

6KB
81 lines

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()));

Dependencies

~0.8–1.3MB
~26K SLoC