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},
};
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<Result<Uri, Infallible>>;
type Future = Ready<Result<Self, Self::Error>>;
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<Result<Method, Infallible>>;
type Future = Ready<Result<Self, Self::Error>>;
type Config = ();
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_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<Result<ConnectionInfo, Infallible>>;
type Future = Ready<Result<Self, Self::Error>>;
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;