From 3c00bf59c4853e58249d65a1b7a0d7d1b5708f49 Mon Sep 17 00:00:00 2001 From: Ben Saunders Date: Wed, 9 Aug 2023 13:35:58 -0700 Subject: [PATCH] Privatize TransportParameters::default() --- quinn-proto/src/connection/streams/state.rs | 8 ++++---- quinn-proto/src/transport_parameters.rs | 11 +++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/quinn-proto/src/connection/streams/state.rs b/quinn-proto/src/connection/streams/state.rs index 07f6d199e..a701d31bd 100644 --- a/quinn-proto/src/connection/streams/state.rs +++ b/quinn-proto/src/connection/streams/state.rs @@ -1168,7 +1168,7 @@ mod tests { initial_max_streams_uni: 1u32.into(), initial_max_data: 42u32.into(), initial_max_stream_data_uni: 42u32.into(), - ..Default::default() + ..TransportParameters::default() }); let (mut pending, state) = (Retransmits::default(), ConnState::Established); @@ -1227,7 +1227,7 @@ mod tests { initial_max_streams_bidi: 3u32.into(), initial_max_data: 10u32.into(), initial_max_stream_data_bidi_remote: 10u32.into(), - ..Default::default() + ..TransportParameters::default() }); let (mut pending, state) = (Retransmits::default(), ConnState::Established); @@ -1283,7 +1283,7 @@ mod tests { initial_max_streams_bidi: 3u32.into(), initial_max_data: 1000u32.into(), initial_max_stream_data_bidi_remote: 1000u32.into(), - ..Default::default() + ..TransportParameters::default() }); let (mut pending, state) = (Retransmits::default(), ConnState::Established); @@ -1377,7 +1377,7 @@ mod tests { initial_max_streams_uni: 1u32.into(), initial_max_data: 42u32.into(), initial_max_stream_data_uni: 42u32.into(), - ..Default::default() + ..TransportParameters::default() }); let (mut pending, state) = (Retransmits::default(), ConnState::Established); let mut streams = Streams { diff --git a/quinn-proto/src/transport_parameters.rs b/quinn-proto/src/transport_parameters.rs index 9335858a8..78a3e18c7 100644 --- a/quinn-proto/src/transport_parameters.rs +++ b/quinn-proto/src/transport_parameters.rs @@ -101,9 +101,12 @@ macro_rules! make_struct { pub(crate) preferred_address: Option, } - impl Default for TransportParameters { + // We deliberately don't implement the `Default` trait, since that would be public, and + // downstream crates should never construct `TransportParameters` except by decoding those + // supplied by a peer. + impl TransportParameters { /// Standard defaults, used if the peer does not supply a given parameter. - fn default() -> Self { + pub(crate) fn default() -> Self { Self { $($name: VarInt::from_u32($default),)* @@ -528,11 +531,11 @@ mod test { fn resumption_params_validation() { let high_limit = TransportParameters { initial_max_streams_uni: 32u32.into(), - ..Default::default() + ..TransportParameters::default() }; let low_limit = TransportParameters { initial_max_streams_uni: 16u32.into(), - ..Default::default() + ..TransportParameters::default() }; high_limit.validate_resumption_from(&low_limit).unwrap(); low_limit.validate_resumption_from(&high_limit).unwrap_err();