Skip to main content

tcplane/common/
type.rs

1use crate::*;
2
3/// A type alias for `Arc<RwLock<T>>`.
4///
5/// Provides thread-safe shared ownership with read-write access.
6pub type ArcRwLock<T> = Arc<RwLock<T>>;
7
8/// A type alias for read guard of `ArcRwLock<T>`.
9pub type ArcRwLockReadGuard<'a, T> = RwLockReadGuard<'a, T>;
10
11/// A type alias for write guard of `ArcRwLock<T>`.
12pub type ArcRwLockWriteGuard<'a, T> = RwLockWriteGuard<'a, T>;
13
14/// A type alias for a hash map with `Arc<dyn Any + Send + Sync>` values.
15pub type HashMapArcAnySendSync = HashMap<String, Arc<dyn Any + Send + Sync>>;
16
17/// A type alias for an optional socket address.
18pub type OptionSocketAddr = Option<SocketAddr>;
19
20/// A type alias for an optional socket host (IP address).
21pub type OptionSocketHost = Option<std::net::IpAddr>;
22
23/// A type alias for an optional socket port.
24pub type OptionSocketPort = Option<u16>;
25
26/// A type alias for response data (byte vector).
27pub type ResponseData = Vec<u8>;
28
29/// A type alias for response result.
30pub type ResponseResult = Result<(), ResponseError>;
31
32/// A type alias for error handling function.
33pub type ErrorHandleFn = dyn Fn(String) + Send + Sync;
34
35/// A type alias for arc-wrapped error handling function.
36pub type ArcErrorHandle = Arc<ErrorHandleFn>;
37
38/// A type alias for server hook handler function.
39pub type ServerHookHandler =
40    Arc<dyn Fn(Context) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + Sync>;
41
42/// A type alias for a list of server hook handlers.
43pub type ServerHookList = Vec<ServerHookHandler>;