diff --git a/viz-core/src/request.rs b/viz-core/src/request.rs index 1c071c58..c21b635e 100644 --- a/viz-core/src/request.rs +++ b/viz-core/src/request.rs @@ -47,6 +47,10 @@ pub trait RequestExt: Sized { fn query_string(&self) -> Option<&str>; /// Get query data by type. + /// + /// # Errors + /// + /// Will return [`PayloadError::UrlDecode`] if decoding the query string fails. #[cfg(feature = "query")] fn query(&self) -> Result where @@ -78,6 +82,11 @@ pub trait RequestExt: Sized { fn incoming_body(&mut self) -> IncomingBody; /// Get Incoming. + /// + /// # Errors + /// + /// Will return [`PayloadError::Empty`] or [`PayloadError::Used`] if the incoming does not + /// exist or be used. fn incoming(&mut self) -> Result; /// Return with a [Bytes][mdn] representation of the request body. @@ -85,10 +94,10 @@ pub trait RequestExt: Sized { /// [mdn]: async fn bytes(&mut self) -> Result; - #[cfg(feature = "limits")] /// Return with a [Bytes][mdn] by a limit representation of the request body. /// /// [mdn]: + #[cfg(feature = "limits")] async fn bytes_with(&mut self, limit: Option, max: u64) -> Result; /// Return with a [Text][mdn] representation of the request body. @@ -96,28 +105,28 @@ pub trait RequestExt: Sized { /// [mdn]: async fn text(&mut self) -> Result; - #[cfg(feature = "form")] /// Return with a `application/x-www-form-urlencoded` [FormData][mdn] by the specified type /// representation of the request body. /// /// [mdn]: + #[cfg(feature = "form")] async fn form(&mut self) -> Result where T: serde::de::DeserializeOwned; - #[cfg(feature = "json")] /// Return with a [JSON][mdn] by the specified type representation of the request body. /// /// [mdn]: + #[cfg(feature = "json")] async fn json(&mut self) -> Result where T: serde::de::DeserializeOwned; - #[cfg(feature = "multipart")] /// Return with a `multipart/form-data` [FormData][mdn] by the specified type /// representation of the request body. /// /// [mdn]: + #[cfg(feature = "multipart")] async fn multipart(&mut self) -> Result; #[cfg(feature = "state")] @@ -126,38 +135,50 @@ pub trait RequestExt: Sized { where T: Clone + Send + Sync + 'static; - #[cfg(feature = "state")] /// Store a shared state. + #[cfg(feature = "state")] fn set_state(&mut self, t: T) -> Option where T: Clone + Send + Sync + 'static; - #[cfg(feature = "cookie")] /// Get a wrapper of `cookie-jar` for managing cookies. + /// + /// # Errors + /// + /// Will return [`CookiesError`] if getting cookies fails. + #[cfg(feature = "cookie")] fn cookies(&self) -> Result; - #[cfg(feature = "cookie")] /// Get a cookie by the specified name. + #[cfg(feature = "cookie")] fn cookie(&self, name: S) -> Option> where S: AsRef; - #[cfg(feature = "limits")] /// Get limits settings. + #[cfg(feature = "limits")] fn limits(&self) -> &Limits; - #[cfg(feature = "session")] /// Get current session. + #[cfg(feature = "session")] fn session(&self) -> &Session; - #[cfg(feature = "params")] /// Get all parameters. + /// + /// # Errors + /// + /// Will return [`ParamsError`] if deserializer the parameters fails. + #[cfg(feature = "params")] fn params(&self) -> Result where T: serde::de::DeserializeOwned; - #[cfg(feature = "params")] /// Get single parameter by name. + /// + /// # Errors + /// + /// Will return [`ParamsError`] if deserializer the single parameter fails. + #[cfg(feature = "params")] fn param(&self, name: &str) -> Result where T: std::str::FromStr,