Skip to main content

ntex_util/
lib.rs

1//! Utilities for ntex framework
2#![deny(clippy::pedantic)]
3#![allow(
4    async_fn_in_trait,
5    clippy::missing_fields_in_debug,
6    clippy::must_use_candidate,
7    clippy::missing_errors_doc,
8    clippy::missing_panics_doc,
9    clippy::unused_async_trait_impl
10)]
11use std::{error::Error, io, rc::Rc};
12
13pub mod channel;
14pub mod future;
15pub mod services;
16pub mod task;
17pub mod time;
18
19pub use futures_core::Stream;
20pub use ntex_rt::spawn;
21
22#[doc(hidden)]
23pub use hashbrown::{Equivalent, hash_map, hash_set};
24
25pub type HashMap<K, V> = hash_map::HashMap<K, V, foldhash::fast::RandomState>;
26pub type HashSet<V> = hash_set::HashSet<V, foldhash::fast::RandomState>;
27pub type HashRandomState = foldhash::fast::RandomState;
28
29pub fn dyn_err<E: Error + 'static>(e: E) -> Box<dyn Error> {
30    let e: Box<dyn Error> = Box::new(e);
31    e
32}
33
34pub fn dyn_rc_err<T: Error + 'static>(err: T) -> Rc<dyn Error> {
35    Rc::new(err)
36}
37
38pub fn str_rc_err(s: String) -> Rc<dyn Error> {
39    #[derive(thiserror::Error, Debug)]
40    #[error("{_0}")]
41    struct StringError(String);
42
43    Rc::new(StringError(s))
44}
45
46pub fn clone_io_error(err: &io::Error) -> io::Error {
47    io::Error::new(err.kind(), format!("{err:?}"))
48}