Skip to main content

ntex/
lib.rs

1//! ntex - framework for composable network services
2//!
3//! ## Package feature
4//!
5//! * `openssl` - enables ssl support via `openssl` crate
6//! * `rustls` - enables ssl support via `rustls` crate
7//! * `compress` - enables compression support in http and web modules
8//! * `cookie` - enables cookie support in http and web modules
9#![deny(clippy::pedantic)]
10#![allow(
11    type_alias_bounds,
12    missing_debug_implementations,
13    clippy::cast_possible_truncation,
14    clippy::missing_errors_doc,
15    clippy::missing_fields_in_debug,
16    clippy::missing_panics_doc,
17    clippy::must_use_candidate,
18    clippy::too_many_lines,
19    clippy::type_complexity
20)]
21// Used for fake variadics
22#![cfg_attr(any(docsrs, docsrs_dep), feature(rustdoc_internals))]
23
24#[cfg(not(test))] // Work around for rust-lang/rust#62127
25pub use ntex_macros::{rt_main as main, rt_test as test};
26
27#[cfg(test)]
28pub(crate) use ntex_macros::rt_test_internal as rt_test;
29
30pub use ntex_service::{forward_poll, forward_ready, forward_shutdown};
31
32pub mod client;
33pub mod http;
34pub mod web;
35
36#[cfg(feature = "ws")]
37pub mod ws;
38
39pub use self::service::{
40    IntoService, IntoServiceFactory, Middleware, Pipeline, Service, ServiceCtx,
41    ServiceFactory, cfg::Cfg, cfg::SharedCfg, chain, chain_factory, fn_service,
42};
43
44pub use ntex_util::{channel, task};
45
46pub mod codec {
47    //! Utilities for encoding and decoding frames.
48    pub use ntex_codec::*;
49}
50
51pub mod connect {
52    //! Tcp connector service
53    pub use ntex_net::connect::*;
54
55    #[cfg(feature = "openssl")]
56    pub mod openssl {
57        pub use ntex_tls::openssl::*;
58    }
59
60    #[cfg(feature = "rustls")]
61    pub mod rustls {
62        pub use ntex_tls::rustls::*;
63    }
64}
65
66pub mod router {
67    //! Resource path matching library.
68    pub use ntex_router::*;
69}
70
71pub mod rt {
72    //! A runtime implementation that runs everything on the current thread.
73    pub use ntex_rt::*;
74
75    pub use ntex_net::*;
76}
77
78pub mod service {
79    pub use ntex_service::*;
80}
81
82pub mod server {
83    //! General purpose tcp server
84    pub use ntex_server::net::*;
85
86    pub use ntex_server::{Signal, signal};
87
88    #[cfg(feature = "openssl")]
89    pub use ntex_tls::openssl;
90
91    #[cfg(feature = "rustls")]
92    pub use ntex_tls::rustls;
93}
94
95pub mod time {
96    //! Utilities for tracking time.
97    pub use ntex_util::time::*;
98}
99
100pub mod io {
101    //! IO streaming utilities.
102    pub use ntex_dispatcher::*;
103    pub use ntex_io::*;
104}
105
106pub mod testing {
107    //! IO testing utilities.
108    pub use ntex_io::testing::IoTest;
109}
110
111pub mod tls {
112    //! TLS support for ntex ecosystem.
113    pub use ntex_tls::*;
114}
115
116pub mod error {
117    pub use ntex_error::*;
118
119    #[doc(hidden)]
120    #[allow(deprecated)]
121    pub use ntex_error::ErrorType;
122}
123
124pub mod util {
125    use std::{error::Error, io, rc::Rc};
126
127    pub use ntex_bytes::{Buf, BufMut, ByteString, Bytes, BytesMut};
128    pub use ntex_util::{HashMap, HashSet, future::*, services::*};
129
130    #[doc(hidden)]
131    #[allow(deprecated)]
132    pub use ntex_util::error::*;
133
134    #[doc(hidden)]
135    pub fn enable_test_logging() {
136        #[cfg(not(feature = "no-test-logging"))]
137        if std::env::var("NTEX_NO_TEST_LOG").is_err() {
138            if std::env::var("RUST_LOG").is_err() {
139                unsafe {
140                    std::env::set_var("RUST_LOG", "trace");
141                }
142            }
143            let _ = env_logger::builder().is_test(true).try_init();
144        }
145    }
146
147    pub fn dyn_rc_error<T: Error + 'static>(err: T) -> Rc<dyn Error> {
148        Rc::new(err)
149    }
150
151    pub fn str_rc_error(s: String) -> Rc<dyn Error> {
152        #[derive(thiserror::Error, Debug)]
153        #[error("{_0}")]
154        struct StringError(String);
155
156        Rc::new(StringError(s))
157    }
158
159    pub fn clone_io_error(err: &io::Error) -> io::Error {
160        io::Error::new(err.kind(), format!("{err:?}"))
161    }
162}