add `Method` example

This commit is contained in:
Ibraheem Ahmed 2021-06-22 11:16:15 -04:00 committed by GitHub
parent 73e852c7a9
commit 39446fe262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -254,6 +254,22 @@ impl FromRequest for Version {
}
}
/// Extract the request's method.
///
/// ## Example
///
/// ```
/// use actix_web::{web, App, HttpRequest, http::Method};
///
/// async fn index(method: Method) -> &'static str {
/// assert_eq!(method, Method::GET);
/// "Welcome!"
/// }
///
/// fn main() {
/// let app = App::new().route("/", web::get().to(index));
/// }
/// ```
impl FromRequest for Method {
type Error = Infallible;
type Future = Ready<Result<Method, Infallible>>;