From 9ec3cc0fe70089f22f72dfb083d81f456380afc7 Mon Sep 17 00:00:00 2001 From: david-mcgillicuddy-moixa <51170803+david-mcgillicuddy-moixa@users.noreply.github.com> Date: Mon, 10 Jan 2022 17:00:04 +0000 Subject: [PATCH] Replace str_split_once to lower actix-tls msrv to 1.50.0 and bump actix-net to 1.50.0 (#434) --- actix-tls/CHANGES.md | 2 +- actix-tls/src/connect/host.rs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/actix-tls/CHANGES.md b/actix-tls/CHANGES.md index e491f0af..13bb37b2 100644 --- a/actix-tls/CHANGES.md +++ b/actix-tls/CHANGES.md @@ -1,7 +1,7 @@ # Changes ## Unreleased - 2021-xx-xx - +- Remove use of `str::split_once` to lower MSRV of `actix-tls` to a de-facto 1.50.0 from 1.52.0 ## 3.0.0 - 2021-12-26 * No significant changes since `3.0.0-rc.2`. diff --git a/actix-tls/src/connect/host.rs b/actix-tls/src/connect/host.rs index c4ff9a01..13780751 100644 --- a/actix-tls/src/connect/host.rs +++ b/actix-tls/src/connect/host.rs @@ -27,25 +27,25 @@ pub trait Host: Unpin + 'static { impl Host for String { fn hostname(&self) -> &str { - self.split_once(':') + str_split_once(self, ':') .map(|(hostname, _)| hostname) .unwrap_or(self) } fn port(&self) -> Option { - self.split_once(':').and_then(|(_, port)| port.parse().ok()) + str_split_once(self, ':').and_then(|(_, port)| port.parse().ok()) } } impl Host for &'static str { fn hostname(&self) -> &str { - self.split_once(':') + str_split_once(self, ':') .map(|(hostname, _)| hostname) .unwrap_or(self) } fn port(&self) -> Option { - self.split_once(':').and_then(|(_, port)| port.parse().ok()) + str_split_once(self, ':').and_then(|(_, port)| port.parse().ok()) } } @@ -69,3 +69,11 @@ mod tests { assert_connection_info_eq!("example.com:false:false", "example.com", None); } } + +// `str::split_once` is stabilized in 1.52.0 +fn str_split_once(str: &str, delimiter: char) -> Option<(&str, &str)> { + let mut splitn = str.splitn(2, delimiter); + let prefix = splitn.next()?; + let suffix = splitn.next()?; + Some((prefix, suffix)) +}