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
use crate::jsonrpc::futures::sync::mpsc;
use crate::jsonrpc::Metadata;
use crate::server_utils::session;
pub struct RequestContext<'a> {
pub session_id: session::SessionId,
pub endpoint_addr: &'a ::parity_tokio_ipc::RemoteId,
pub sender: mpsc::Sender<String>,
}
pub trait MetaExtractor<M: Metadata>: Send + Sync + 'static {
fn extract(&self, context: &RequestContext) -> M;
}
impl<M, F> MetaExtractor<M> for F
where
M: Metadata,
F: Fn(&RequestContext) -> M + Send + Sync + 'static,
{
fn extract(&self, context: &RequestContext) -> M {
(*self)(context)
}
}
pub struct NoopExtractor;
impl<M: Metadata + Default> MetaExtractor<M> for NoopExtractor {
fn extract(&self, _context: &RequestContext) -> M {
M::default()
}
}