From 6877539af491ea1ee29d24ab48eff2e6bac33aed Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Thu, 14 Jul 2022 12:32:30 -0700 Subject: [PATCH] Add convenient GossipSync variant constructors These constructors fill in the missing types for each variant so that users don't have to turbofish them manually. --- lightning-background-processor/src/lib.rs | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 11dca44bb..484439b39 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -137,6 +137,55 @@ where A::Target: chain::Access, L::Target: Logger { } } +/// (C-not exported) as the bindings concretize everything and have constructors for us +impl>, G: Deref>, A: Deref, L: Deref> + GossipSync, G, A, L> +where + A::Target: chain::Access, + L::Target: Logger, +{ + /// Initializes a new [`GossipSync::P2P`] variant. + pub fn p2p(gossip_sync: P) -> Self { + GossipSync::P2P(gossip_sync) + } +} + +/// (C-not exported) as the bindings concretize everything and have constructors for us +impl<'a, R: Deref>, G: Deref>, L: Deref> + GossipSync< + &P2PGossipSync, + R, + G, + &'a (dyn chain::Access + Send + Sync), + L, + > +where + L::Target: Logger, +{ + /// Initializes a new [`GossipSync::Rapid`] variant. + pub fn rapid(gossip_sync: R) -> Self { + GossipSync::Rapid(gossip_sync) + } +} + +/// (C-not exported) as the bindings concretize everything and have constructors for us +impl<'a, L: Deref> + GossipSync< + &P2PGossipSync<&'a NetworkGraph, &'a (dyn chain::Access + Send + Sync), L>, + &RapidGossipSync<&'a NetworkGraph, L>, + &'a NetworkGraph, + &'a (dyn chain::Access + Send + Sync), + L, + > +where + L::Target: Logger, +{ + /// Initializes a new [`GossipSync::None`] variant. + pub fn none() -> Self { + GossipSync::None + } +} + /// Decorates an [`EventHandler`] with common functionality provided by standard [`EventHandler`]s. struct DecoratingEventHandler< 'a, -- 2.39.5