Skip to content

Commit d37b7fc

Browse files
wpaulinoG8XSU
authored andcommitted
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.
1 parent a3547e2 commit d37b7fc

File tree

1 file changed

+49
-0
lines changed
  • lightning-background-processor/src

1 file changed

+49
-0
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,55 @@ where A::Target: chain::Access, L::Target: Logger {
137137
}
138138
}
139139

140+
/// (C-not exported) as the bindings concretize everything and have constructors for us
141+
impl<P: Deref<Target = P2PGossipSync<G, A, L>>, G: Deref<Target = NetworkGraph<L>>, A: Deref, L: Deref>
142+
GossipSync<P, &RapidGossipSync<G, L>, G, A, L>
143+
where
144+
A::Target: chain::Access,
145+
L::Target: Logger,
146+
{
147+
/// Initializes a new [`GossipSync::P2P`] variant.
148+
pub fn p2p(gossip_sync: P) -> Self {
149+
GossipSync::P2P(gossip_sync)
150+
}
151+
}
152+
153+
/// (C-not exported) as the bindings concretize everything and have constructors for us
154+
impl<'a, R: Deref<Target = RapidGossipSync<G, L>>, G: Deref<Target = NetworkGraph<L>>, L: Deref>
155+
GossipSync<
156+
&P2PGossipSync<G, &'a (dyn chain::Access + Send + Sync), L>,
157+
R,
158+
G,
159+
&'a (dyn chain::Access + Send + Sync),
160+
L,
161+
>
162+
where
163+
L::Target: Logger,
164+
{
165+
/// Initializes a new [`GossipSync::Rapid`] variant.
166+
pub fn rapid(gossip_sync: R) -> Self {
167+
GossipSync::Rapid(gossip_sync)
168+
}
169+
}
170+
171+
/// (C-not exported) as the bindings concretize everything and have constructors for us
172+
impl<'a, L: Deref>
173+
GossipSync<
174+
&P2PGossipSync<&'a NetworkGraph<L>, &'a (dyn chain::Access + Send + Sync), L>,
175+
&RapidGossipSync<&'a NetworkGraph<L>, L>,
176+
&'a NetworkGraph<L>,
177+
&'a (dyn chain::Access + Send + Sync),
178+
L,
179+
>
180+
where
181+
L::Target: Logger,
182+
{
183+
/// Initializes a new [`GossipSync::None`] variant.
184+
pub fn none() -> Self {
185+
GossipSync::None
186+
}
187+
}
188+
140189
/// Decorates an [`EventHandler`] with common functionality provided by standard [`EventHandler`]s.
141190
struct DecoratingEventHandler<
142191
'a,

0 commit comments

Comments
 (0)