1use std::{any, fmt, marker::PhantomData, net::SocketAddr};
3
4#[derive(Copy, Clone, PartialEq, Eq)]
5pub struct PeerAddr(pub SocketAddr);
6
7impl PeerAddr {
8 pub fn into_inner(self) -> SocketAddr {
9 self.0
10 }
11}
12
13impl From<SocketAddr> for PeerAddr {
14 fn from(addr: SocketAddr) -> Self {
15 Self(addr)
16 }
17}
18
19impl fmt::Debug for PeerAddr {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 self.0.fmt(f)
22 }
23}
24
25#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
26pub enum HttpProtocol {
28 Http1,
29 Http2,
30 Unknown,
31}
32
33pub struct QueryItem<T> {
34 item: Option<Box<dyn any::Any>>,
35 _t: PhantomData<T>,
36}
37
38impl<T: any::Any> QueryItem<T> {
39 pub(crate) fn new(item: Option<Box<dyn any::Any>>) -> Self {
40 Self {
41 item,
42 _t: PhantomData,
43 }
44 }
45
46 pub fn get(&self) -> Option<T>
47 where
48 T: Copy,
49 {
50 self.item.as_ref().and_then(|v| v.downcast_ref().copied())
51 }
52
53 pub fn as_ref(&self) -> Option<&T> {
54 if let Some(ref item) = self.item {
55 item.downcast_ref()
56 } else {
57 None
58 }
59 }
60}
61
62impl<T: any::Any + fmt::Debug> fmt::Debug for QueryItem<T> {
63 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64 if let Some(v) = self.as_ref() {
65 f.debug_tuple("QueryItem").field(v).finish()
66 } else {
67 f.debug_tuple("QueryItem").field(&None::<T>).finish()
68 }
69 }
70}