1use futures::Stream;
2use std::fmt::Debug;
3use std::{
4 pin::Pin,
5 task::{Context, Poll},
6};
7
8pub trait Discovery: sealed::Sealed {
9 type Key: Debug;
13
14 type Element;
18
19 type Error;
23
24 fn poll_change(
28 self: Pin<&mut Self>,
29 cx: &mut Context<'_>,
30 ) -> Poll<Option<Result<Change<Self::Key, Self::Element>, Self::Error>>>;
31}
32
33pub enum Change<K, V> {
34 Insert(K, V),
38
39 Remove(K),
43
44 Initialized,
48}
49
50impl<S, K, T, E> sealed::Sealed for S where S: Stream<Item = Result<Change<K, T>, E>> {}
51
52impl<S, K, T, E> Discovery for S
53where
54 S: Stream<Item = Result<Change<K, T>, E>>,
55 K: Debug,
56{
57 type Key = K;
58
59 type Element = T;
60
61 type Error = E;
62
63 fn poll_change(
64 self: Pin<&mut Self>,
65 cx: &mut Context<'_>,
66 ) -> Poll<Option<Result<Change<Self::Key, Self::Element>, Self::Error>>> {
67 self.poll_next(cx)
68 }
69}
70
71pub type BoxDiscovery<'a, K, I, E> =
72 Pin<Box<dyn Stream<Item = Result<Change<K, I>, E>> + Send + Sync + 'a>>;
73
74mod sealed {
75 pub trait Sealed {}
76}