diff --git a/aquatic_udp/src/lib/handlers/announce.rs b/aquatic_udp/src/lib/handlers/announce.rs index 9c718ac..5d73f54 100644 --- a/aquatic_udp/src/lib/handlers/announce.rs +++ b/aquatic_udp/src/lib/handlers/announce.rs @@ -52,7 +52,7 @@ pub fn handle_announce_requests( } else { Response::Error(ErrorResponse { transaction_id: request.transaction_id, - message: "Info hash not allowed".to_string(), + message: "Info hash not allowed".into(), }) }; diff --git a/aquatic_udp/src/lib/handlers/mod.rs b/aquatic_udp/src/lib/handlers/mod.rs index dab6baf..a1906d9 100644 --- a/aquatic_udp/src/lib/handlers/mod.rs +++ b/aquatic_udp/src/lib/handlers/mod.rs @@ -143,6 +143,6 @@ pub fn run_request_worker( fn create_invalid_connection_response(transaction_id: TransactionId) -> Response { Response::Error(ErrorResponse { transaction_id, - message: "Connection invalid or expired".to_string(), + message: "Connection invalid or expired".into(), }) } diff --git a/aquatic_udp/src/lib/network.rs b/aquatic_udp/src/lib/network.rs index 6f64885..d0a5506 100644 --- a/aquatic_udp/src/lib/network.rs +++ b/aquatic_udp/src/lib/network.rs @@ -152,9 +152,9 @@ fn read_requests( if let Some(transaction_id) = err.transaction_id { let opt_message = if err.error.is_some() { - Some("Parse error".to_string()) + Some("Parse error".into()) } else if let Some(message) = err.message { - Some(message) + Some(message.into()) } else { None }; diff --git a/aquatic_udp_protocol/src/response.rs b/aquatic_udp_protocol/src/response.rs index abe76ff..c785759 100644 --- a/aquatic_udp_protocol/src/response.rs +++ b/aquatic_udp_protocol/src/response.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::convert::TryInto; use std::io::{self, Cursor, Write}; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; @@ -37,7 +38,7 @@ pub struct ScrapeResponse { #[derive(PartialEq, Eq, Clone, Debug)] pub struct ErrorResponse { pub transaction_id: TransactionId, - pub message: String, + pub message: Cow<'static, str>, } #[derive(PartialEq, Eq, Clone, Debug)] @@ -224,7 +225,7 @@ impl Response { Ok((ErrorResponse { transaction_id: TransactionId(transaction_id), - message: String::from_utf8_lossy(&inner[position..]).into(), + message: String::from_utf8_lossy(&inner[position..]).into_owned().into(), }) .into()) } @@ -262,7 +263,7 @@ impl Response { } _ => Ok((ErrorResponse { transaction_id: TransactionId(transaction_id), - message: "Invalid action".to_string(), + message: "Invalid action".into(), }) .into()), }