1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#![forbid(unsafe_code)]
#![deny(missing_docs)]
#[doc(hidden)]
pub use choices_derive::*;
pub mod bytes {
pub use bytes::*;
}
pub mod warp {
pub use warp::*;
}
#[cfg(feature = "json")]
pub mod serde_json {
pub use serde_json::*;
}
#[doc(hidden)]
pub use async_trait::*;
pub mod error;
pub use crate::error::{ChoicesError, ChoicesResult};
pub mod serde;
pub use crate::serde::{ChoicesInput, ChoicesOutput};
use std::net::SocketAddr;
use std::sync::{Arc, Mutex, RwLock};
#[self::async_trait]
pub trait Choices {
async fn run<T: Into<SocketAddr> + Send>(&'static self, addr: T);
#[doc(hidden)]
async fn run_mutable<T: Into<SocketAddr> + Send>(_: Arc<Mutex<Self>>, _: T) {
unimplemented!()
}
#[doc(hidden)]
async fn run_mutable_rw<T: Into<SocketAddr> + Send>(_: Arc<RwLock<Self>>, _: T)
where
Self: Sync,
{
unimplemented!()
}
}
#[self::async_trait]
impl<C: Choices + Send> Choices for Arc<Mutex<C>> {
async fn run<T: Into<SocketAddr> + Send>(&'static self, addr: T) {
C::run_mutable(self.clone(), addr).await;
}
}
#[self::async_trait]
impl<C: Choices + Send + Sync> Choices for Arc<RwLock<C>> {
async fn run<T: Into<SocketAddr> + Send>(&'static self, addr: T) {
C::run_mutable_rw(self.clone(), addr).await;
}
}