jsonrpc_tcp_server/
meta.rsuse std::net::SocketAddr;
use crate::jsonrpc::{futures::channel::mpsc, Metadata};
pub struct RequestContext {
pub peer_addr: SocketAddr,
pub sender: mpsc::UnboundedSender<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()
}
}