serf_core/delegate/
reconnect.rs

1use std::time::Duration;
2
3use memberlist_core::{CheapClone, transport::Id};
4
5use crate::types::Member;
6
7/// Implemented to allow overriding the reconnect timeout for individual members.
8#[auto_impl::auto_impl(Box, Arc)]
9pub trait ReconnectDelegate: Send + Sync + 'static {
10  /// The id type of the delegate
11  type Id: Id;
12  /// The address type of the delegate
13  type Address: CheapClone + Send + Sync + 'static;
14
15  /// Returns the reconnect timeout for the given member.
16  fn reconnect_timeout(
17    &self,
18    member: &Member<Self::Id, Self::Address>,
19    timeout: Duration,
20  ) -> Duration;
21}
22
23/// Noop implementation of `ReconnectDelegate`.
24#[derive(Debug)]
25pub struct NoopReconnectDelegate<I, A>(std::marker::PhantomData<(I, A)>);
26
27impl<I, A> Default for NoopReconnectDelegate<I, A> {
28  fn default() -> Self {
29    Self(Default::default())
30  }
31}
32
33impl<I, A> Clone for NoopReconnectDelegate<I, A> {
34  fn clone(&self) -> Self {
35    *self
36  }
37}
38
39impl<I, A> Copy for NoopReconnectDelegate<I, A> {}
40
41impl<I, A> ReconnectDelegate for NoopReconnectDelegate<I, A>
42where
43  I: Id + Send + Sync + 'static,
44  A: CheapClone + Send + Sync + 'static,
45{
46  type Id = I;
47  type Address = A;
48
49  fn reconnect_timeout(
50    &self,
51    _member: &Member<Self::Id, Self::Address>,
52    timeout: Duration,
53  ) -> Duration {
54    timeout
55  }
56}