tokio_listener/
lib.rs

1#![cfg_attr(docsrs_alt, feature(doc_cfg))]
2#![warn(missing_docs)]
3#![allow(clippy::useless_conversion, clippy::module_name_repetitions)]
4//! Library for abstracting over TCP server sockets, UNIX server sockets, inetd-like mode.
5//!
6//! [`ListenerAddress`] is like `SocketAddr` and [`Listener`] is like `TcpListener`, but with more flexibility.
7//!
8//! ```,no_run
9//! # tokio_test::block_on(async {
10//! # use tokio_listener::*;
11//! let addr1 : ListenerAddress = "127.0.0.1:8087".parse().unwrap();
12//! let addr2 : ListenerAddress = "/path/to/socket".parse().unwrap();
13//! let addr3 : ListenerAddress = "@abstract_linux_address".parse().unwrap();
14//!
15//! let system_options : SystemOptions = Default::default();
16//! let user_options : UserOptions = Default::default();
17//!
18//! let mut l = Listener::bind(&addr1, &system_options, &user_options).await.unwrap();
19//! while let Ok((conn, addr)) = l.accept().await {
20//!     // ...
21//! }
22//! # });
23//! ```
24//!
25//!  There is special integration with `clap`:
26//!
27//! ```,no_run
28//! # #[cfg(feature="clap")] {
29//! use clap::Parser;
30//!
31//! #[derive(Parser)]
32//! /// Demo application for tokio-listener
33//! struct Args {
34//!     #[clap(flatten)]
35//!     listener: tokio_listener::ListenerAddressPositional,
36//! }
37//!
38//! # tokio_test::block_on(async {
39//! let args = Args::parse();
40//!
41//! let listener = args.listener.bind().await.unwrap();
42//!
43//! let app = axum06::Router::new().route("/", axum06::routing::get(|| async { "Hello, world\n" }));
44//!
45//! axum06::Server::builder(listener).serve(app.into_make_service()).await;
46//! # }) }
47//! ```
48//!
49//! See project [README](https://github.com/vi/tokio-listener/blob/main/README.md) for details and more examples.
50//!
51//! ## Feature flags
52#![doc = document_features::document_features!()]
53//!
54//! Disabling default features bring tokio-listener close to usual `TcpListener`.
55
56#![cfg_attr(not(feature = "sd_listen"), deny(unsafe_code))]
57#![cfg_attr(
58    not(feature = "default"),
59    allow(unused_imports, irrefutable_let_patterns, unused_variables)
60)]
61
62mod connection;
63mod error;
64mod listener;
65mod listener_address;
66mod options;
67mod some_socket_addr;
68mod tcp_keepalive_params;
69mod unix_chmod;
70
71#[cfg(feature = "unix_path_tools")]
72#[doc(inline)]
73pub use unix_chmod::UnixChmodVariant;
74
75#[cfg(feature = "socket_options")]
76#[doc(inline)]
77pub use tcp_keepalive_params::TcpKeepaliveParams;
78
79#[doc(inline)]
80pub use options::{SystemOptions, UserOptions};
81
82#[doc(inline)]
83pub use listener_address::ListenerAddress;
84
85#[doc(inline)]
86pub use listener::Listener;
87
88#[allow(unused_imports)]
89pub(crate) use listener::is_connection_error;
90
91#[doc(inline)]
92pub use connection::Connection;
93
94#[doc(inline)]
95pub use some_socket_addr::{SomeSocketAddr, SomeSocketAddrClonable};
96
97#[cfg(feature = "clap")]
98#[cfg_attr(docsrs_alt, doc(cfg(feature = "clap")))]
99mod claptools;
100
101#[cfg(feature = "clap")]
102pub use claptools::{ListenerAddressLFlag, ListenerAddressPositional};
103
104#[cfg(feature = "hyper014")]
105#[cfg_attr(docsrs_alt, doc(cfg(feature = "hyper014")))]
106mod hyper014;
107
108/// Analogue of `axum::serve` module, but for tokio-listener.
109#[cfg(feature = "axum07")]
110#[cfg_attr(docsrs_alt, doc(cfg(feature = "axum07")))]
111pub mod axum07;
112
113#[cfg(feature = "tonic010")]
114#[cfg_attr(docsrs_alt, doc(cfg(feature = "tonic010")))]
115mod tonic010;
116
117#[cfg(feature = "tonic011")]
118#[cfg_attr(docsrs_alt, doc(cfg(feature = "tonic011")))]
119mod tonic011;
120
121#[cfg(feature = "tonic012")]
122#[cfg_attr(docsrs_alt, doc(cfg(feature = "tonic012")))]
123mod tonic012;
124
125#[cfg(feature = "tokio-util")]
126#[cfg_attr(docsrs_alt, doc(cfg(feature = "tokio-util")))]
127mod tokioutil;
128
129#[doc(inline)]
130pub use error::{AcceptError, BindError};