diff --git a/viz-core/src/into_response.rs b/viz-core/src/into_response.rs index 978113f5..0aff2e22 100644 --- a/viz-core/src/into_response.rs +++ b/viz-core/src/into_response.rs @@ -111,7 +111,7 @@ where fn into_response(self) -> Response { self.map_or_else( || StatusCode::NOT_FOUND.into_response(), - |r| r.into_response(), + IntoResponse::into_response, ) } } diff --git a/viz-core/src/middleware/helper.rs b/viz-core/src/middleware/helper.rs index f0239f36..2099a4c4 100644 --- a/viz-core/src/middleware/helper.rs +++ b/viz-core/src/middleware/helper.rs @@ -70,7 +70,7 @@ impl CookieOptions { /// Creates new `CookieOptions` with `http_only` #[must_use] - pub fn http_only(mut self, http_only: bool) -> Self { + pub const fn http_only(mut self, http_only: bool) -> Self { self.http_only = http_only; self } diff --git a/viz-core/src/response.rs b/viz-core/src/response.rs index 6da0398c..5545b050 100644 --- a/viz-core/src/response.rs +++ b/viz-core/src/response.rs @@ -226,13 +226,10 @@ impl ResponseExt for Response { let value = name .map_or_else( || { - if let Some(filename) = - path.as_ref().file_name().and_then(std::ffi::OsStr::to_str) - { - filename - } else { - "download" - } + path.as_ref() + .file_name() + .and_then(std::ffi::OsStr::to_str) + .map_or("download", |filename| filename) }, |filename| filename, ) diff --git a/viz-core/src/types/cookie.rs b/viz-core/src/types/cookie.rs index 0d5d3132..4a884493 100644 --- a/viz-core/src/types/cookie.rs +++ b/viz-core/src/types/cookie.rs @@ -226,7 +226,7 @@ pub enum CookiesError { impl From for Error { fn from(e: CookiesError) -> Self { - Error::Responder(e.into_response()) + Self::Responder(e.into_response()) } } diff --git a/viz-core/src/types/header.rs b/viz-core/src/types/header.rs index bcbd63b1..9df63ba9 100644 --- a/viz-core/src/types/header.rs +++ b/viz-core/src/types/header.rs @@ -16,7 +16,7 @@ pub struct Header(pub T); impl Header { /// Create new `Header` instance. #[inline] - pub fn new(t: T) -> Self { + pub const fn new(t: T) -> Self { Self(t) } diff --git a/viz-core/src/types/session.rs b/viz-core/src/types/session.rs index fbef5a31..f33dd7a1 100644 --- a/viz-core/src/types/session.rs +++ b/viz-core/src/types/session.rs @@ -54,17 +54,15 @@ impl Session { where T: DeserializeOwned, { - let read = self - .lock_data() + self.lock_data() .read() - .map_err(|e| responder_error((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())))?; - - let val = read.get(key).cloned(); - - match val { - Some(t) => from_value(t).map(Some).map_err(report_error), - None => Ok(None), - } + .map_err(|e| responder_error((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())))? + .get(key) + .cloned() + .map_or_else( + || Ok(None), + |t| from_value(t).map(Some).map_err(report_error), + ) } /// Sets a value by the key