aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-02 01:23:33 +0000
committerFuwn <[email protected]>2023-04-02 01:23:33 +0000
commitb2858ff245f0f1b8a16ff9ca9180eb305c5e4fee (patch)
treeddabcc44c720d835910e7759beeb95b906956772 /src
parentfeat(router): expose response to post-route callback (diff)
downloadwindmark-b2858ff245f0f1b8a16ff9ca9180eb305c5e4fee.tar.xz
windmark-b2858ff245f0f1b8a16ff9ca9180eb305c5e4fee.zip
refactor(src): clean up string generics
Diffstat (limited to 'src')
-rw-r--r--src/response.rs32
-rw-r--r--src/router.rs43
2 files changed, 43 insertions, 32 deletions
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<S>(content: S) -> Self
- where S: Into<String> + AsRef<str> {
- 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<String> + AsRef<str>,
+ ) -> Self {
Self::new(21, String::from_utf8_lossy(content))
.with_mime(mime)
.clone()
@@ -100,8 +103,7 @@ impl Response {
}
#[must_use]
- pub fn new<S>(status: i32, content: S) -> Self
- where S: Into<String> + AsRef<str> {
+ pub fn new(status: i32, content: impl Into<String> + AsRef<str>) -> Self {
Self {
status,
mime: None,
@@ -111,22 +113,28 @@ impl Response {
}
}
- pub fn with_mime<S>(&mut self, mime: S) -> &mut Self
- where S: Into<String> + AsRef<str> {
+ pub fn with_mime(
+ &mut self,
+ mime: impl Into<String> + AsRef<str>,
+ ) -> &mut Self {
self.mime = Some(mime.into());
self
}
- pub fn with_character_set<S>(&mut self, character_set: S) -> &mut Self
- where S: Into<String> + AsRef<str> {
+ pub fn with_character_set(
+ &mut self,
+ character_set: impl Into<String> + AsRef<str>,
+ ) -> &mut Self {
self.character_set = Some(character_set.into());
self
}
- pub fn with_language<S>(&mut self, language: S) -> &mut Self
- where S: Into<String> + AsRef<str> {
+ pub fn with_language(
+ &mut self,
+ language: impl Into<String> + AsRef<str>,
+ ) -> &mut Self {
self.language = Some(language.into());
self
diff --git a/src/router.rs b/src/router.rs
index b2c0435..04e955e 100644
--- a/src/router.rs
+++ b/src/router.rs
@@ -93,13 +93,10 @@ impl Router {
/// ```rust
/// windmark::Router::new().set_private_key_file("windmark_private.pem");
/// ```
- pub fn set_private_key_file<S>(
+ pub fn set_private_key_file(
&mut self,
- private_key_file_name: S,
- ) -> &mut Self
- where
- S: Into<String> + AsRef<str>,
- {
+ private_key_file_name: impl Into<String> + AsRef<str>,
+ ) -> &mut Self {
self.private_key_file_name = private_key_file_name.into();
self
@@ -112,8 +109,10 @@ impl Router {
/// ```rust
/// windmark::Router::new().set_certificate_file("windmark_public.pem");
/// ```
- pub fn set_certificate_file<S>(&mut self, certificate_name: S) -> &mut Self
- where S: Into<String> + AsRef<str> {
+ pub fn set_certificate_file(
+ &mut self,
+ certificate_name: impl Into<String> + AsRef<str>,
+ ) -> &mut Self {
self.ca_file_name = certificate_name.into();
self
@@ -140,8 +139,11 @@ impl Router {
/// # Panics
///
/// if the route cannot be mounted.
- pub fn mount<S>(&mut self, route: S, handler: RouteResponse) -> &mut Self
- where S: Into<String> + AsRef<str> {
+ pub fn mount(
+ &mut self,
+ route: impl Into<String> + AsRef<str>,
+ handler: RouteResponse,
+ ) -> &mut Self {
self
.routes
.insert(route.into(), Arc::new(Mutex::new(handler)))
@@ -518,14 +520,11 @@ impl Router {
/// // .set_log_level("your_crate_name=trace", false);
/// ```
#[cfg(feature = "logger")]
- pub fn set_log_level<S>(
+ pub fn set_log_level(
&mut self,
- log_level: S,
+ log_level: impl Into<String> + AsRef<str>,
log_windmark: bool,
- ) -> &mut Self
- where
- S: Into<String> + AsRef<str>,
- {
+ ) -> &mut Self {
std::env::set_var(
"RUST_LOG",
format!(
@@ -699,8 +698,10 @@ impl Router {
/// ```rust
/// windmark::Router::new().set_character_set("utf-8");
/// ```
- pub fn set_character_set<S>(&mut self, character_set: S) -> &mut Self
- where S: Into<String> + AsRef<str> {
+ pub fn set_character_set(
+ &mut self,
+ character_set: impl Into<String> + AsRef<str>,
+ ) -> &mut Self {
self.character_set = character_set.into();
self
@@ -717,8 +718,10 @@ impl Router {
/// ```rust
/// windmark::Router::new().set_language("en");
/// ```
- pub fn set_language<S>(&mut self, language: S) -> &mut Self
- where S: Into<String> + AsRef<str> {
+ pub fn set_language(
+ &mut self,
+ language: impl Into<String> + AsRef<str>,
+ ) -> &mut Self {
self.language = language.into();
self