diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 458b1f393d5..b3be900341b 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -199,17 +199,11 @@ 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| { + self.cache_config + .unwrap_or_default() + .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 {