From b2858ff245f0f1b8a16ff9ca9180eb305c5e4fee Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 2 Apr 2023 01:23:33 +0000 Subject: refactor(src): clean up string generics --- src/response.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src/response.rs') diff --git a/src/response.rs b/src/response.rs index 9c1629a..c693ac8 100644 --- a/src/response.rs +++ b/src/response.rs @@ -75,9 +75,9 @@ impl Response { response!(certificate_not_valid, 62); - pub fn success(content: S) -> Self - where S: Into + AsRef { - Self::new(20, content.into()) + #[allow(clippy::needless_pass_by_value)] + pub fn success(content: impl ToString) -> Self { + Self::new(20, content.to_string()) .with_mime("text/gemini") .with_language("en") .with_character_set("utf-8") @@ -85,7 +85,10 @@ impl Response { } #[must_use] - pub fn binary_success(content: &[u8], mime: &str) -> Self { + pub fn binary_success( + content: &[u8], + mime: impl Into + AsRef, + ) -> Self { Self::new(21, String::from_utf8_lossy(content)) .with_mime(mime) .clone() @@ -100,8 +103,7 @@ impl Response { } #[must_use] - pub fn new(status: i32, content: S) -> Self - where S: Into + AsRef { + pub fn new(status: i32, content: impl Into + AsRef) -> Self { Self { status, mime: None, @@ -111,22 +113,28 @@ impl Response { } } - pub fn with_mime(&mut self, mime: S) -> &mut Self - where S: Into + AsRef { + pub fn with_mime( + &mut self, + mime: impl Into + AsRef, + ) -> &mut Self { self.mime = Some(mime.into()); self } - pub fn with_character_set(&mut self, character_set: S) -> &mut Self - where S: Into + AsRef { + pub fn with_character_set( + &mut self, + character_set: impl Into + AsRef, + ) -> &mut Self { self.character_set = Some(character_set.into()); self } - pub fn with_language(&mut self, language: S) -> &mut Self - where S: Into + AsRef { + pub fn with_language( + &mut self, + language: impl Into + AsRef, + ) -> &mut Self { self.language = Some(language.into()); self -- cgit v1.2.3