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
use std::net::SocketAddr;
use crate::jsonrpc::futures::sync::mpsc;
use crate::jsonrpc::Metadata;
pub struct RequestContext {
	
	pub peer_addr: SocketAddr,
	
	pub sender: mpsc::Sender<String>,
}
pub trait MetaExtractor<M: Metadata>: Send + Sync {
	
	fn extract(&self, context: &RequestContext) -> M;
}
impl<M, F> MetaExtractor<M> for F
where
	M: Metadata,
	F: Fn(&RequestContext) -> M + Send + Sync,
{
	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()
	}
}