From e36038b6e30d3228e24e92d4eedd95ed09b31bf2 Mon Sep 17 00:00:00 2001 From: monosans Date: Fri, 15 Aug 2025 12:28:43 +0300 Subject: [PATCH] refactor: rename proxy.as_str to proxy.to_string for clarity --- src/checker.rs | 2 +- src/output.rs | 2 +- src/proxy.rs | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/checker.rs b/src/checker.rs index d0ab137..3131937 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -58,7 +58,7 @@ pub async fn check_all( Err(e) if tracing::event_enabled!(tracing::Level::DEBUG) => { tracing::debug!( "{} | {}", - proxy.as_str(true), + proxy.to_string(true), pretty_error(&e) ); } diff --git a/src/output.rs b/src/output.rs index ff4235b..eb82a51 100644 --- a/src/output.rs +++ b/src/output.rs @@ -240,6 +240,6 @@ where { proxies .into_iter() - .map(move |proxy| proxy.as_str(include_protocol)) + .map(move |proxy| proxy.to_string(include_protocol)) .join("\n") } diff --git a/src/proxy.rs b/src/proxy.rs index d67c5b8..0a897d9 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -1,4 +1,5 @@ use std::{ + fmt::Write as _, hash::{Hash, Hasher}, str::FromStr, sync::Arc, @@ -131,12 +132,14 @@ impl Proxy { Ok(()) } - pub fn as_str(&self, include_protocol: bool) -> String { + pub fn to_string(&self, include_protocol: bool) -> String { let mut s = String::new(); + if include_protocol { s.push_str(self.protocol.as_str()); s.push_str("://"); } + if let (Some(username), Some(password)) = (&self.username, &self.password) { @@ -145,9 +148,11 @@ impl Proxy { s.push_str(password); s.push('@'); } + s.push_str(&self.host); s.push(':'); - s.push_str(&self.port.to_string()); + write!(s, "{}", self.port).unwrap(); + s } }