1use crate::impl_::router::Router as RouterImpl;
2use crate::SodiumCtx;
3use crate::Stream;
4use std::hash::Hash;
5
6pub struct Router<A, K> {
10 impl_: RouterImpl<A, K>,
11}
12
13impl<A, K> Router<A, K> {
14 pub fn new(
17 sodium_ctx: &SodiumCtx,
18 in_stream: &Stream<A>,
19 selector: impl Fn(&A) -> Vec<K> + Send + Sync + 'static,
20 ) -> Router<A, K>
21 where
22 A: Clone + Send + 'static,
23 K: Send + Sync + Eq + Hash + 'static,
24 {
25 Router {
26 impl_: RouterImpl::new(&sodium_ctx.impl_, &in_stream.impl_, selector),
27 }
28 }
29
30 pub fn filter_matches(&self, k: &K) -> Stream<A>
33 where
34 A: Clone + Send + 'static,
35 K: Clone + Send + Sync + Eq + Hash + 'static,
36 {
37 Stream {
38 impl_: self.impl_.filter_matches(k),
39 }
40 }
41}