rs_jsonrpc_tcp_server/
meta.rs

1use std::net::SocketAddr;
2
3use jsonrpc::futures::sync::mpsc;
4use jsonrpc::Metadata;
5
6/// Request context
7pub struct RequestContext {
8	/// Peer Address
9	pub peer_addr: SocketAddr,
10	/// Peer Sender channel
11	pub sender: mpsc::Sender<String>,
12}
13
14/// Metadata extractor (per session)
15pub trait MetaExtractor<M: Metadata> : Send + Sync {
16	/// Extracts metadata from request context
17	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
29/// Noop-extractor
30pub struct NoopExtractor;
31impl<M: Metadata> MetaExtractor<M> for NoopExtractor {
32	fn extract(&self, _context: &RequestContext) -> M { M::default() }
33}