The Accept<I, S> trait allows you to intercept and modify the IO stream and the service produced during the connection acceptance phase. This is useful for applying configurations (like socket options) or wrapping the service before it is handed off to the server.
To implement it, you must define:
Stream: The type of the IO stream (e.g., TcpStream).Service: The type of the service produced.Future: An asynchronous operation that returns io::Result<(Self::Stream, Self::Service)>.
use axum_server::Accept;
use std::io;
use tokio::net::TcpStream;
struct MyCustomAcceptor;
impl<S> Accept<TcpStream, S> for MyCustomAcceptor {
type Stream = TcpStream;
type Service = S;
type Future = std::future::Ready<io::Result<(Self::Stream, Self::Service)>>;
fn accept(&self, stream: TcpStream, service: S) -> Self::Future {
// Perform custom logic here, e.g., setting socket options
std::future::ready(Ok((stream, service)))
}
}