From 1b1412230b8ce50fc489c88a00ce5377e8d42938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20RIBEAU?= Date: Fri, 6 Sep 2024 10:03:07 +0200 Subject: [PATCH] don't make PeerAddressesConfig attributes public --- protocols/identify/src/behaviour.rs | 15 ++++----------- swarm/src/behaviour/peer_addresses.rs | 4 ++-- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 458b1f393d5..621f8f9a531 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -199,17 +199,10 @@ impl Config { /// Configures the size of the LRU cache, caching addresses of discovered peers. #[deprecated(since = "0.45.1", note = "Use `Config::with_cache_config` instead.")] pub fn with_cache_size(mut self, cache_size: usize) -> Self { - match NonZeroUsize::new(cache_size) { - Some(cache_size) => { - if let Some(cache_config) = &mut self.cache_config { - cache_config.number_of_peers = cache_size; - } else { - self.cache_config = - Some(PeerAddressesConfig::default().with_number_of_peers(cache_size)) - } - } - None => self.cache_config = None, - } + self.cache_config = NonZeroUsize::new(cache_size).map(|cache_size| { + let cache_config = self.cache_config.unwrap_or_default(); + cache_config.with_number_of_peers(cache_size) + }); self } diff --git a/swarm/src/behaviour/peer_addresses.rs b/swarm/src/behaviour/peer_addresses.rs index f689c1f5ab2..dd489124d11 100644 --- a/swarm/src/behaviour/peer_addresses.rs +++ b/swarm/src/behaviour/peer_addresses.rs @@ -12,10 +12,10 @@ use std::num::NonZeroUsize; /// Configuration of a [`PeerAddresses`] instance. pub struct PeerAddressesConfig { /// Capacity of the [`PeerAddresses`] cache. - pub number_of_peers: NonZeroUsize, + number_of_peers: NonZeroUsize, /// Maximum number of cached addresses per peer. - pub number_of_addresses_per_peer: NonZeroUsize, + number_of_addresses_per_peer: NonZeroUsize, } impl PeerAddressesConfig {