Skip to content

Commit b401729

Browse files
feat(builder): add with_quic shortcut for smol provider on TcpPhase
Add macro impl_tcp_phase_with_quic to provide with_quic() and with_quic_config() methods on TcpPhase for both Tokio and Smol providers. This allows users to skip TCP and go directly to QUIC when using the smol runtime. Previously, with_quic() on TcpPhase was only available for Tokio, causing a compilation error when trying to use: SwarmBuilder::with_smol().with_quic() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 974b109 commit b401729

File tree

1 file changed

+27
-22
lines changed
  • libp2p/src/builder/phase

1 file changed

+27
-22
lines changed

libp2p/src/builder/phase/tcp.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,34 @@ impl<Provider> SwarmBuilder<Provider, TcpPhase> {
115115
}
116116
}
117117

118-
#[cfg(all(not(target_arch = "wasm32"), feature = "quic", feature = "tokio"))]
119-
impl SwarmBuilder<super::provider::Tokio, TcpPhase> {
120-
pub fn with_quic(
121-
self,
122-
) -> SwarmBuilder<
123-
super::provider::Tokio,
124-
OtherTransportPhase<impl AuthenticatedMultiplexedTransport>,
125-
> {
126-
self.without_tcp().with_quic()
127-
}
128-
}
129-
#[cfg(all(not(target_arch = "wasm32"), feature = "quic", feature = "tokio"))]
130-
impl SwarmBuilder<super::provider::Tokio, TcpPhase> {
131-
pub fn with_quic_config(
132-
self,
133-
constructor: impl FnOnce(libp2p_quic::Config) -> libp2p_quic::Config,
134-
) -> SwarmBuilder<
135-
super::provider::Tokio,
136-
OtherTransportPhase<impl AuthenticatedMultiplexedTransport>,
137-
> {
138-
self.without_tcp().with_quic_config(constructor)
139-
}
118+
macro_rules! impl_tcp_phase_with_quic {
119+
($providerKebabCase:literal, $providerPascalCase:ty) => {
120+
#[cfg(all(not(target_arch = "wasm32"), feature = "quic", feature = $providerKebabCase))]
121+
impl SwarmBuilder<$providerPascalCase, TcpPhase> {
122+
pub fn with_quic(
123+
self,
124+
) -> SwarmBuilder<
125+
$providerPascalCase,
126+
OtherTransportPhase<impl AuthenticatedMultiplexedTransport>,
127+
> {
128+
self.without_tcp().with_quic()
129+
}
130+
131+
pub fn with_quic_config(
132+
self,
133+
constructor: impl FnOnce(libp2p_quic::Config) -> libp2p_quic::Config,
134+
) -> SwarmBuilder<
135+
$providerPascalCase,
136+
OtherTransportPhase<impl AuthenticatedMultiplexedTransport>,
137+
> {
138+
self.without_tcp().with_quic_config(constructor)
139+
}
140+
}
141+
};
140142
}
143+
144+
impl_tcp_phase_with_quic!("tokio", super::provider::Tokio);
145+
impl_tcp_phase_with_quic!("smol", super::provider::Smol);
141146
impl<Provider> SwarmBuilder<Provider, TcpPhase> {
142147
pub fn with_other_transport<
143148
Muxer: libp2p_core::muxing::StreamMuxer + Send + 'static,

0 commit comments

Comments
 (0)