jsonrpc_tcp_server/
meta.rs1use std::net::SocketAddr;
2
3use crate::jsonrpc::{futures::channel::mpsc, Metadata};
4
5pub struct RequestContext {
7 pub peer_addr: SocketAddr,
9 pub sender: mpsc::UnboundedSender<String>,
11}
12
13pub trait MetaExtractor<M: Metadata>: Send + Sync {
15 fn extract(&self, context: &RequestContext) -> M;
17}
18
19impl<M, F> MetaExtractor<M> for F
20where
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 + Default> MetaExtractor<M> for NoopExtractor {
32 fn extract(&self, _context: &RequestContext) -> M {
33 M::default()
34 }
35}