From 70835edd20967793b5b564122dd6c59297b71257 Mon Sep 17 00:00:00 2001 From: Chris Connelly Date: Tue, 21 Sep 2021 17:24:03 +0100 Subject: [PATCH] refactor!: use `&RetryConfig` for retry overrides This is primarily in preparation for changing `Endpoint::retry_config` to `Arc` so that it can be efficiently shared with `Connection`s. It also quite likely that callers would have common `RetryConfig` inside a static or const, so this may also avoid some additional cloning on the caller end. More generally, since we don't need ownership, asking for a reference allows for more global efficiency since the caller gets to use a reference if they have one. BREAKING CHANGE: The `Endpoint::send_message_with` and `Endpoint::try_send_message_with` methods now take `retries` as an `Option<&RetryConfig>`, rather than `Option`. --- src/endpoint.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/endpoint.rs b/src/endpoint.rs index 97335323..87f09497 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -456,13 +456,13 @@ impl Endpoint { msg: Bytes, dest: &SocketAddr, priority: i32, - retries: Option, + retries: Option<&RetryConfig>, ) -> Result<(), Option> { if let Some((conn, guard)) = self.connection_pool.get_by_addr(dest).await { trace!("Connection exists in the connection pool: {}", dest); let connection = Connection::new(conn, guard); retries - .unwrap_or(self.config.retry_config) + .unwrap_or(&self.config.retry_config) .retry(|| async { Ok(connection.send_uni(msg.clone(), priority).await?) }) .await?; Ok(()) @@ -522,11 +522,11 @@ impl Endpoint { msg: Bytes, dest: &SocketAddr, priority: i32, - retries: Option, + retries: Option<&RetryConfig>, ) -> Result<(), SendError> { let connection = self.get_or_connect_to(dest).await?; retries - .unwrap_or(self.config.retry_config) + .unwrap_or(&self.config.retry_config) .retry(|| async { Ok(connection.send_uni(msg.clone(), priority).await?) }) .await?;