From 60c72412c7ffbb3dc0bd8181d4d22164d8387e3f Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 22 Jun 2021 16:51:50 +0100 Subject: [PATCH] standardize new docs format --- src/extract.rs | 30 ++++++++++++------------------ src/info.rs | 18 ++++++++---------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/extract.rs b/src/extract.rs index 2f5acde33..d7b67cd90 100644 --- a/src/extract.rs +++ b/src/extract.rs @@ -7,7 +7,7 @@ use std::{ task::{Context, Poll}, }; -use actix_http::http::{Method, Uri, Version}; +use actix_http::http::{Method, Uri}; use actix_utils::future::{ok, Ready}; use futures_core::ready; @@ -218,24 +218,21 @@ where } } -/// Extract the request's uri. -/// -/// ## Example +/// Extract the request's URI. /// +/// # Examples /// ``` -/// use actix_web::{web, App, HttpRequest, http::Uri}; +/// use actix_web::{http::Uri, web, App, Responder}; /// -/// async fn index(uri: Uri) -> String { +/// async fn handler(uri: Uri) -> impl Responder { /// format!("Requested path: {}", uri.path()) /// } /// -/// fn main() { -/// let app = App::new().route("/", web::get().to(index)); -/// } +/// let app = App::new().default_service(web::to(handler)); /// ``` impl FromRequest for Uri { type Error = Infallible; - type Future = Ready>; + type Future = Ready>; type Config = (); fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { @@ -245,22 +242,19 @@ impl FromRequest for Uri { /// Extract the request's method. /// -/// ## Example -/// +/// # Examples /// ``` -/// use actix_web::{web, App, HttpRequest, http::Method}; +/// use actix_web::{http::Method, web, App, Responder}; /// -/// async fn index(method: Method) -> String { +/// async fn handler(method: Method) -> impl Responder { /// format!("Request method: {}", method) /// } /// -/// fn main() { -/// let app = App::new().route("/", web::get().to(index)); -/// } +/// let app = App::new().default_service(web::to(handler)); /// ``` impl FromRequest for Method { type Error = Infallible; - type Future = Ready>; + type Future = Ready>; type Config = (); fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { diff --git a/src/info.rs b/src/info.rs index 8c2d521aa..c6ff54efe 100644 --- a/src/info.rs +++ b/src/info.rs @@ -13,26 +13,23 @@ const X_FORWARDED_FOR: &[u8] = b"x-forwarded-for"; const X_FORWARDED_HOST: &[u8] = b"x-forwarded-host"; const X_FORWARDED_PROTO: &[u8] = b"x-forwarded-proto"; -/// `HttpRequest` connection information +/// HTTP connection information. /// /// `ConnectionInfo` implements `FromRequest` and can be extracted in handlers. /// -/// ## Example -/// +/// # Examples /// ``` -/// use actix_web::{web, App, HttpRequest, HttpResponse, dev::ConnectionInfo}; +/// # use actix_web::{HttpResponse, Responder}; +/// use actix_web::dev::ConnectionInfo; /// -/// async fn index(conn: ConnectionInfo) -> HttpResponse { +/// async fn handler(conn: ConnectionInfo) -> impl Responder { /// match conn.host() { /// "actix.rs" => HttpResponse::Ok().body("Welcome!"), /// "admin.actix.rs" => HttpResponse::Ok().body("Admin portal."), /// _ => HttpResponse::NotFound().finish() /// } /// } -/// -/// fn main() { -/// let app = App::new().route("/", web::get().to(index)); -/// } +/// # let _svc = actix_web::web::to(handler); /// ``` #[derive(Debug, Clone, Default)] pub struct ConnectionInfo { @@ -215,7 +212,7 @@ impl ConnectionInfo { impl FromRequest for ConnectionInfo { type Error = Infallible; - type Future = Ready>; + type Future = Ready>; type Config = (); fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { @@ -250,6 +247,7 @@ impl PeerAddr { } #[derive(Debug, Display, Error)] +#[non_exhaustive] #[display(fmt = "Missing peer address")] pub struct MissingPeerAddr;