diff --git a/viz-core/src/body.rs b/viz-core/src/body.rs index ecb37c4d..99e0108a 100644 --- a/viz-core/src/body.rs +++ b/viz-core/src/body.rs @@ -9,8 +9,8 @@ use hyper::body::{Body, Frame, Incoming, SizeHint}; use crate::{Bytes, Error, Result}; -#[derive(Debug)] /// Incoming Body from request. +#[derive(Debug)] pub enum IncomingBody { /// A empty body. Empty, @@ -107,8 +107,8 @@ impl Stream for IncomingBody { } } -#[derive(Debug)] /// Outgoing Body to response. +#[derive(Debug)] pub enum OutgoingBody { /// A empty body. Empty, diff --git a/viz-core/src/middleware/cookie.rs b/viz-core/src/middleware/cookie.rs index 4fcb5244..4ba4a39b 100644 --- a/viz-core/src/middleware/cookie.rs +++ b/viz-core/src/middleware/cookie.rs @@ -15,8 +15,8 @@ pub struct Config { } impl Config { - #[cfg(any(feature = "cookie-signed", feature = "cookie-private"))] /// Creates a new config with the [`Key`][types::CookieKey]. + #[cfg(any(feature = "cookie-signed", feature = "cookie-private"))] #[must_use] pub fn with_key(key: types::CookieKey) -> Self { Self { diff --git a/viz-core/src/middleware/helper.rs b/viz-core/src/middleware/helper.rs index 4b3630f9..351729aa 100644 --- a/viz-core/src/middleware/helper.rs +++ b/viz-core/src/middleware/helper.rs @@ -123,8 +123,8 @@ impl Default for CookieOptions { } } -#[cfg(not(feature = "cookie-private"))] /// An interface for managing the cookies. +#[cfg(not(feature = "cookie-private"))] pub trait Cookieable { /// Gets the options of the cookie. fn options(&self) -> &CookieOptions; @@ -145,8 +145,8 @@ pub trait Cookieable { } } -#[cfg(feature = "cookie-private")] /// An interface for managing the `private` cookies. +#[cfg(feature = "cookie-private")] pub trait Cookieable { /// Gets the options of the cookie. fn options(&self) -> &CookieOptions; diff --git a/viz-core/src/middleware/limits.rs b/viz-core/src/middleware/limits.rs index 3fb37c68..2591ff41 100644 --- a/viz-core/src/middleware/limits.rs +++ b/viz-core/src/middleware/limits.rs @@ -27,8 +27,8 @@ impl Config { self } - #[cfg(feature = "multipart")] /// Sets a limits for the Multipart Form. + #[cfg(feature = "multipart")] #[must_use] pub fn multipart(mut self, limits: types::MultipartLimits) -> Self { *Arc::make_mut(&mut self.multipart) = limits; diff --git a/viz-core/src/request.rs b/viz-core/src/request.rs index c21b635e..19d795cf 100644 --- a/viz-core/src/request.rs +++ b/viz-core/src/request.rs @@ -129,8 +129,8 @@ pub trait RequestExt: Sized { #[cfg(feature = "multipart")] async fn multipart(&mut self) -> Result; - #[cfg(feature = "state")] /// Return a shared state by the specified type. + #[cfg(feature = "state")] fn state(&self) -> Option where T: Clone + Send + Sync + 'static; diff --git a/viz-core/src/response.rs b/viz-core/src/response.rs index 16decb52..b685c5f1 100644 --- a/viz-core/src/response.rs +++ b/viz-core/src/response.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "json")] -use bytes::{BufMut, BytesMut}; use http_body_util::Full; use crate::{header, Bytes, Error, OutgoingBody, Response, Result, StatusCode}; @@ -40,17 +38,20 @@ pub trait ResponseExt: Sized { Self::with(body.into(), mime::TEXT_HTML_UTF_8.as_ref()) } - #[cfg(feature = "json")] /// The response with `application/javascript; charset=utf-8` media type. /// /// # Errors /// /// Throws an error if serialization fails. + #[cfg(feature = "json")] fn json(body: T) -> Result where T: serde::Serialize, { - let mut buf = BytesMut::new().writer(); + use bytes::{BufMut, BytesMut}; + + // See + let mut buf = BytesMut::with_capacity(128).writer(); serde_json::to_writer(&mut buf, &body) .map(|()| { Self::with(