rs_jsonrpc_tcp_server/
meta.rs1use std::net::SocketAddr;
2
3use jsonrpc::futures::sync::mpsc;
4use jsonrpc::Metadata;
5
6pub struct RequestContext {
8 pub peer_addr: SocketAddr,
10 pub sender: mpsc::Sender<String>,
12}
13
14pub trait MetaExtractor<M: Metadata> : Send + Sync {
16 fn extract(&self, context: &RequestContext) -> M;
18}
19
20impl<M, F> MetaExtractor<M> for F where
21 M: Metadata,
22 F: Fn(&RequestContext) -> M + Send + Sync,
23{
24 fn extract(&self, context: &RequestContext) -> M {
25 (*self)(context)
26 }
27}
28
29pub struct NoopExtractor;
31impl<M: Metadata> MetaExtractor<M> for NoopExtractor {
32 fn extract(&self, _context: &RequestContext) -> M { M::default() }
33}