pub enum DualListener {
Tcp(TcpListener),
Uds(UnixListener),
}Expand description
A unified listener that can bind to either TCP or Unix Domain Socket addresses.
This enum allows you to create a single listener type that can handle both TCP and UDS
connections transparently. The specific variant is determined at runtime based on the
address format provided to DualListener::bind.
§Examples
use axum_listener::listener::DualListener;
// Bind to TCP
let tcp_listener = DualListener::bind("localhost:8080").await.unwrap();
// Bind to Unix Domain Socket (on Unix systems)
let uds_listener = DualListener::bind("unix:/tmp/app.sock").await.unwrap();§Platform Support
Tcpvariant is available on all platformsUdsvariant is only available on Unix-like systems
Variants§
Tcp(TcpListener)
A TCP listener for network connections
Uds(UnixListener)
A Unix Domain Socket listener for local inter-process communication
Implementations§
Source§impl DualListener
impl DualListener
Sourcepub async fn bind<A: ToDualAddr>(address: A) -> Result<Self, Error>
pub async fn bind<A: ToDualAddr>(address: A) -> Result<Self, Error>
Creates a new DualListener bound to the specified address.
This method accepts any type that implements ToDualAddr, allowing
for flexible address specification. The listener type (TCP or UDS) is
automatically determined based on the address format.
§Arguments
address- An address that can be converted toDualAddr
§Returns
Returns a DualListener bound to the specified address, or an error
if binding fails.
§Examples
use axum_listener::listener::DualListener;
// Bind to TCP address
let listener = DualListener::bind("localhost:8080").await.unwrap();
// Bind to UDS address (Unix only)
let listener = DualListener::bind("unix:/tmp/app.sock").await.unwrap();§Errors
This method can fail if:
- The address format is invalid
- The address is already in use
- Permission is denied for the requested address
- Unix Domain Sockets are not supported on the current platform
Sourcepub async fn accept(&self) -> Result<(DualStream, DualAddr), Error>
pub async fn accept(&self) -> Result<(DualStream, DualAddr), Error>
Accepts a new incoming connection from this listener.
This method will wait for a connection to be established and return a stream and address representing the connection.
§Returns
Returns a tuple containing:
DualStream: The stream for communicating with the clientDualAddr: The address of the connected client
§Examples
use axum_listener::listener::DualListener;
let listener = DualListener::bind("localhost:8080").await.unwrap();
// Accept a connection
let (stream, addr) = listener.accept().await.unwrap();
println!("Accepted connection from: {:?}", addr);§Errors
This method can fail if there’s an I/O error while accepting the connection.