浏览代码

Un-generify transport parameters

It turns out that because the transport addresses need to be owned Strings, they don't need to take a generic Into<String> parameter, as when they're created in connect.rs there's an owned String there anyway, and when they're created from AutoTransport the Into was hiding a clone.
Benjamin Sago 4 年之前
父节点
当前提交
d7b1da9403

+ 3 - 4
dns-transport/src/auto.rs

@@ -16,8 +16,7 @@ pub struct AutoTransport {
 impl AutoTransport {
 
     /// Creates a new automatic transport that connects to the given host.
-    pub fn new(sa: impl Into<String>) -> Self {
-        let addr = sa.into();
+    pub fn new(addr: String) -> Self {
         Self { addr }
     }
 }
@@ -25,7 +24,7 @@ impl AutoTransport {
 
 impl Transport for AutoTransport {
     fn send(&self, request: &Request) -> Result<Response, Error> {
-        let udp_transport = UdpTransport::new(&self.addr);
+        let udp_transport = UdpTransport::new(self.addr.clone());
         let udp_response = udp_transport.send(&request)?;
 
         if ! udp_response.flags.truncated {
@@ -34,7 +33,7 @@ impl Transport for AutoTransport {
 
         debug!("Truncated flag set, so switching to TCP");
 
-        let tcp_transport = TcpTransport::new(&self.addr);
+        let tcp_transport = TcpTransport::new(self.addr.clone());
         let tcp_response = tcp_transport.send(&request)?;
         Ok(tcp_response)
     }

+ 2 - 2
dns-transport/src/https.rs

@@ -18,8 +18,8 @@ pub struct HttpsTransport {
 impl HttpsTransport {
 
     /// Creates a new HTTPS transport that connects to the given URL.
-    pub fn new(url: impl Into<String>) -> Self {
-        Self { url: url.into() }
+    pub fn new(url: String) -> Self {
+        Self { url }
     }
 }
 

+ 1 - 0
dns-transport/src/lib.rs

@@ -13,6 +13,7 @@
 
 #![warn(clippy::all, clippy::pedantic)]
 #![allow(clippy::module_name_repetitions)]
+#![allow(clippy::must_use_candidate)]
 #![allow(clippy::option_if_let_else)]
 #![allow(clippy::pub_enum_variant_names)]
 #![allow(clippy::wildcard_imports)]

+ 2 - 2
dns-transport/src/tcp.rs

@@ -23,8 +23,8 @@ pub struct TcpTransport {
 impl TcpTransport {
 
     /// Creates a new TCP transport that connects to the given host.
-    pub fn new(sa: impl Into<String>) -> Self {
-        Self { addr: sa.into() }
+    pub fn new(addr: String) -> Self {
+        Self { addr }
     }
 }
 

+ 1 - 2
dns-transport/src/tls.rs

@@ -18,8 +18,7 @@ pub struct TlsTransport {
 impl TlsTransport {
 
     /// Creates a new TLS transport that connects to the given host.
-    pub fn new(sa: impl Into<String>) -> Self {
-        let addr = sa.into();
+    pub fn new(addr: String) -> Self {
         Self { addr }
     }
 }

+ 1 - 2
dns-transport/src/udp.rs

@@ -19,8 +19,7 @@ pub struct UdpTransport {
 impl UdpTransport {
 
     /// Creates a new UDP transport that connects to the given host.
-    pub fn new(sa: impl Into<String>) -> Self {
-        let addr = sa.into();
+    pub fn new(addr: String) -> Self {
         Self { addr }
     }
 }

+ 9 - 7
src/connect.rs

@@ -31,14 +31,16 @@ pub enum TransportType {
 
 impl TransportType {
 
-    /// Creates a boxed `Transport` depending on the transport type.
-    pub fn make_transport(self, ns: String) -> Box<dyn Transport> {
+    /// Creates a boxed `Transport` depending on the transport type. The
+    /// parameter will be a URL for the HTTPS transport type, and a
+    /// stringified address for the others.
+    pub fn make_transport(self, param: String) -> Box<dyn Transport> {
         match self {
-            Self::Automatic  => Box::new(AutoTransport::new(ns)),
-            Self::UDP        => Box::new(UdpTransport::new(ns)),
-            Self::TCP        => Box::new(TcpTransport::new(ns)),
-            Self::TLS        => Box::new(TlsTransport::new(ns)),
-            Self::HTTPS      => Box::new(HttpsTransport::new(ns)),
+            Self::Automatic  => Box::new(AutoTransport::new(param)),
+            Self::UDP        => Box::new(UdpTransport::new(param)),
+            Self::TCP        => Box::new(TcpTransport::new(param)),
+            Self::TLS        => Box::new(TlsTransport::new(param)),
+            Self::HTTPS      => Box::new(HttpsTransport::new(param)),
         }
     }
 }