Skip to content

Commit 8ff44d3

Browse files
committed
feat: add docs to form
1 parent cb25f6a commit 8ff44d3

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/extractors/form.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@ use serde::de::DeserializeOwned;
55

66
use crate::{extractors::AsyncFromRequestMut, types::Request};
77

8+
/// Represents a form extracted from an HTTP request body.
9+
///
10+
/// This generic struct wraps the deserialized form data of type `T`.
811
pub struct Form<T>(pub T);
912

13+
/// Implementation of the `AsyncFromRequestMut` trait for extracting form data from an HTTP request.
14+
///
15+
/// This implementation supports asynchronous extraction of form data from requests with the
16+
/// `application/x-www-form-urlencoded` content type. The extracted data is deserialized into
17+
/// the generic type `T`.
1018
impl<'a, T> AsyncFromRequestMut<'a> for Form<T>
1119
where
1220
T: DeserializeOwned + Send,
1321
{
22+
/// Extracts form data from the HTTP request body.
23+
///
24+
/// # Arguments
25+
/// * `req` - A mutable reference to the HTTP request from which the form data is extracted.
26+
///
27+
/// # Returns
28+
/// * `Ok(Form<T>)` - If the request contains valid form data that can be deserialized into type `T`.
29+
/// * `Err` - If the content type is invalid or the form data cannot be parsed or deserialized.
1430
async fn from_request(req: &'a mut Request) -> anyhow::Result<Self> {
1531
if req
1632
.headers()

0 commit comments

Comments
 (0)