standardize new docs format

This commit is contained in:
Rob Ede 2021-06-22 16:51:50 +01:00
parent ec21394668
commit 60c72412c7
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
2 changed files with 20 additions and 28 deletions

View File

@ -7,7 +7,7 @@ use std::{
task::{Context, Poll}, task::{Context, Poll},
}; };
use actix_http::http::{Method, Uri, Version}; use actix_http::http::{Method, Uri};
use actix_utils::future::{ok, Ready}; use actix_utils::future::{ok, Ready};
use futures_core::ready; use futures_core::ready;
@ -218,24 +218,21 @@ where
} }
} }
/// Extract the request's uri. /// Extract the request's URI.
///
/// ## Example
/// ///
/// # 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()) /// format!("Requested path: {}", uri.path())
/// } /// }
/// ///
/// fn main() { /// let app = App::new().default_service(web::to(handler));
/// let app = App::new().route("/", web::get().to(index));
/// }
/// ``` /// ```
impl FromRequest for Uri { impl FromRequest for Uri {
type Error = Infallible; type Error = Infallible;
type Future = Ready<Result<Uri, Infallible>>; type Future = Ready<Result<Self, Self::Error>>;
type Config = (); type Config = ();
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
@ -245,22 +242,19 @@ impl FromRequest for Uri {
/// Extract the request's method. /// 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) /// format!("Request method: {}", method)
/// } /// }
/// ///
/// fn main() { /// let app = App::new().default_service(web::to(handler));
/// let app = App::new().route("/", web::get().to(index));
/// }
/// ``` /// ```
impl FromRequest for Method { impl FromRequest for Method {
type Error = Infallible; type Error = Infallible;
type Future = Ready<Result<Method, Infallible>>; type Future = Ready<Result<Self, Self::Error>>;
type Config = (); type Config = ();
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {

View File

@ -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_HOST: &[u8] = b"x-forwarded-host";
const X_FORWARDED_PROTO: &[u8] = b"x-forwarded-proto"; const X_FORWARDED_PROTO: &[u8] = b"x-forwarded-proto";
/// `HttpRequest` connection information /// HTTP connection information.
/// ///
/// `ConnectionInfo` implements `FromRequest` and can be extracted in handlers. /// `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() { /// match conn.host() {
/// "actix.rs" => HttpResponse::Ok().body("Welcome!"), /// "actix.rs" => HttpResponse::Ok().body("Welcome!"),
/// "admin.actix.rs" => HttpResponse::Ok().body("Admin portal."), /// "admin.actix.rs" => HttpResponse::Ok().body("Admin portal."),
/// _ => HttpResponse::NotFound().finish() /// _ => HttpResponse::NotFound().finish()
/// } /// }
/// } /// }
/// /// # let _svc = actix_web::web::to(handler);
/// fn main() {
/// let app = App::new().route("/", web::get().to(index));
/// }
/// ``` /// ```
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct ConnectionInfo { pub struct ConnectionInfo {
@ -215,7 +212,7 @@ impl ConnectionInfo {
impl FromRequest for ConnectionInfo { impl FromRequest for ConnectionInfo {
type Error = Infallible; type Error = Infallible;
type Future = Ready<Result<ConnectionInfo, Infallible>>; type Future = Ready<Result<Self, Self::Error>>;
type Config = (); type Config = ();
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
@ -250,6 +247,7 @@ impl PeerAddr {
} }
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[non_exhaustive]
#[display(fmt = "Missing peer address")] #[display(fmt = "Missing peer address")]
pub struct MissingPeerAddr; pub struct MissingPeerAddr;