1#![deny(clippy::pedantic)]
14#![allow(
15 async_fn_in_trait,
16 clippy::missing_fields_in_debug,
17 clippy::must_use_candidate,
18 clippy::missing_errors_doc,
19 clippy::missing_panics_doc,
20 clippy::unused_async_trait_impl
21)]
22use std::{error::Error, io, rc::Rc};
23
24pub mod channel;
25pub mod future;
26pub mod services;
27pub mod task;
28pub mod time;
29
30pub use futures_core::Stream;
31pub use ntex_rt::spawn;
32
33#[doc(hidden)]
34pub use hashbrown::{Equivalent, hash_map, hash_set};
35
36pub type HashMap<K, V> = hash_map::HashMap<K, V, foldhash::fast::RandomState>;
38pub type HashSet<V> = hash_set::HashSet<V, foldhash::fast::RandomState>;
40pub type HashRandomState = foldhash::fast::RandomState;
42
43pub fn dyn_err<E: Error + 'static>(e: E) -> Box<dyn Error> {
45 let e: Box<dyn Error> = Box::new(e);
46 e
47}
48
49pub fn dyn_rc_err<T: Error + 'static>(err: T) -> Rc<dyn Error> {
51 Rc::new(err)
52}
53
54pub fn str_rc_err(s: String) -> Rc<dyn Error> {
56 #[derive(thiserror::Error, Debug)]
57 #[error("{_0}")]
58 struct StringError(String);
59
60 Rc::new(StringError(s))
61}
62
63pub fn clone_io_error(err: &io::Error) -> io::Error {
69 io::Error::new(err.kind(), err.to_string())
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 #[test]
77 fn test_clone_io_error() {
78 let err = io::Error::new(io::ErrorKind::TimedOut, "timed out");
79 let cloned = clone_io_error(&err);
80 assert_eq!(cloned.kind(), io::ErrorKind::TimedOut);
81 assert_eq!(cloned.to_string(), err.to_string());
82 assert_eq!(clone_io_error(&cloned).to_string(), "timed out");
83 }
84
85 #[test]
86 fn test_dyn_errors() {
87 let err = io::Error::other("boxed");
88 assert_eq!(dyn_err(err).to_string(), "boxed");
89 assert_eq!(dyn_rc_err(io::Error::other("rc")).to_string(), "rc");
90
91 let err = str_rc_err("string error".to_string());
92 assert_eq!(err.to_string(), "string error");
93 assert!(format!("{err:?}").contains("StringError"));
94 }
95}