Skip to content

Commit f90254a

Browse files
committed
quinn: statically hide default_runtime() if unavailable
1 parent d2cdd65 commit f90254a

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

quinn/src/endpoint.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ use std::{
1111
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
1212
};
1313

14-
#[cfg(all(not(wasm_browser), any(feature = "aws-lc-rs", feature = "ring")))]
14+
#[cfg(all(
15+
not(wasm_browser),
16+
any(feature = "runtime-tokio", feature = "runtime-smol"),
17+
any(feature = "aws-lc-rs", feature = "ring"),
18+
))]
1519
use crate::runtime::default_runtime;
1620
use crate::{
1721
Instant,
@@ -25,7 +29,11 @@ use proto::{
2529
EndpointEvent, ServerConfig,
2630
};
2731
use rustc_hash::FxHashMap;
28-
#[cfg(all(not(wasm_browser), any(feature = "aws-lc-rs", feature = "ring"),))]
32+
#[cfg(all(
33+
not(wasm_browser),
34+
any(feature = "runtime-tokio", feature = "runtime-smol"),
35+
any(feature = "aws-lc-rs", feature = "ring"),
36+
))]
2937
use socket2::{Domain, Protocol, Socket, Type};
3038
use tokio::sync::{Notify, futures::Notified, mpsc};
3139
use tracing::{Instrument, Span};
@@ -67,7 +75,11 @@ impl Endpoint {
6775
///
6876
/// Some environments may not allow creation of dual-stack sockets, in which case an IPv6
6977
/// client will only be able to connect to IPv6 servers. An IPv4 client is never dual-stack.
70-
#[cfg(all(not(wasm_browser), any(feature = "aws-lc-rs", feature = "ring")))] // `EndpointConfig::default()` is only available with these
78+
#[cfg(all(
79+
not(wasm_browser),
80+
any(feature = "runtime-tokio", feature = "runtime-smol"),
81+
any(feature = "aws-lc-rs", feature = "ring"), // `EndpointConfig::default()` is only available with these
82+
))]
7183
pub fn client(addr: SocketAddr) -> io::Result<Self> {
7284
let socket = Socket::new(Domain::for_address(addr), Type::DGRAM, Some(Protocol::UDP))?;
7385
if addr.is_ipv6() {
@@ -97,7 +109,11 @@ impl Endpoint {
97109
/// IPv6 address on Windows will not by default be able to communicate with IPv4
98110
/// addresses. Portable applications should bind an address that matches the family they wish to
99111
/// communicate within.
100-
#[cfg(all(not(wasm_browser), any(feature = "aws-lc-rs", feature = "ring")))] // `EndpointConfig::default()` is only available with these
112+
#[cfg(all(
113+
not(wasm_browser),
114+
any(feature = "runtime-tokio", feature = "runtime-smol"),
115+
any(feature = "aws-lc-rs", feature = "ring"), // `EndpointConfig::default()` is only available with these
116+
))]
101117
pub fn server(config: ServerConfig, addr: SocketAddr) -> io::Result<Self> {
102118
let socket = std::net::UdpSocket::bind(addr)?;
103119
let runtime =

quinn/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ pub use crate::recv_stream::{ReadError, ReadExactError, ReadToEndError, RecvStre
8585
pub use crate::runtime::SmolRuntime;
8686
#[cfg(feature = "runtime-tokio")]
8787
pub use crate::runtime::TokioRuntime;
88-
pub use crate::runtime::{AsyncTimer, AsyncUdpSocket, Runtime, UdpSender, default_runtime};
88+
#[cfg(any(feature = "runtime-tokio", feature = "runtime-smol"))]
89+
pub use crate::runtime::default_runtime;
90+
pub use crate::runtime::{AsyncTimer, AsyncUdpSocket, Runtime, UdpSender};
8991
pub use crate::send_stream::{SendStream, StoppedError, WriteError};
9092

9193
#[cfg(test)]

quinn/src/runtime/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
#[cfg(any(feature = "runtime-tokio", feature = "runtime-smol"))]
2+
use std::sync::Arc;
13
use std::{
24
fmt::{self, Debug},
35
future::Future,
46
io::{self, IoSliceMut},
57
net::SocketAddr,
68
pin::Pin,
7-
sync::Arc,
89
task::{Context, Poll},
910
};
1011

@@ -219,6 +220,7 @@ trait UdpSenderHelperSocket: Send + Sync + 'static {
219220
/// If `runtime-tokio` is enabled and this function is called from within a Tokio runtime context,
220221
/// then `TokioRuntime` is returned. Otherwise, if `runtime-smol` is enabled, `SmolRuntime` is
221222
/// returned. Otherwise, `None` is returned.
223+
#[cfg(any(feature = "runtime-tokio", feature = "runtime-smol"))]
222224
#[allow(clippy::needless_return)] // Be sure we return the right thing
223225
pub fn default_runtime() -> Option<Arc<dyn Runtime>> {
224226
#[cfg(feature = "runtime-tokio")]

0 commit comments

Comments
 (0)