1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-27 10:39:03 +02:00

update tests and clippy warnings

This commit is contained in:
Nikolay Kim
2019-12-08 12:31:16 +06:00
parent 6c9f9fff73
commit 4a8a9ef405
22 changed files with 152 additions and 201 deletions

View File

@ -38,7 +38,7 @@ pub struct App<T, B> {
data_factories: Vec<FnDataFactory>,
config: AppConfigInner,
external: Vec<ResourceDef>,
_t: PhantomData<(B)>,
_t: PhantomData<B>,
}
impl App<AppEntry, Body> {
@ -93,13 +93,11 @@ where
/// HttpResponse::Ok()
/// }
///
/// fn main() {
/// let app = App::new()
/// .data(MyData{ counter: Cell::new(0) })
/// .service(
/// web::resource("/index.html").route(
/// web::get().to(index)));
/// }
/// let app = App::new()
/// .data(MyData{ counter: Cell::new(0) })
/// .service(
/// web::resource("/index.html").route(
/// web::get().to(index)));
/// ```
pub fn data<U: 'static>(mut self, data: U) -> Self {
self.data.push(Box::new(Data::new(data)));

View File

@ -195,6 +195,7 @@ macro_rules! tuple_from_req ({$fut_type:ident, $(($n:tt, $T:ident)),+} => {
/// FromRequest implementation for tuple
#[doc(hidden)]
#[allow(unused_parens)]
impl<$($T: FromRequest + 'static),+> FromRequest for ($($T,)+)
{
type Error = Error;

View File

@ -259,16 +259,15 @@ impl Guard for HeaderGuard {
/// Return predicate that matches if request contains specified Host name.
///
/// ```rust,ignore
/// # extern crate actix_web;
/// use actix_web::{guard::Host, App, HttpResponse};
/// ```rust
/// use actix_web::{web, guard::Host, App, HttpResponse};
///
/// fn main() {
/// App::new().resource("/index.html", |r| {
/// r.route()
/// App::new().service(
/// web::resource("/index.html")
/// .guard(Host("www.rust-lang.org"))
/// .f(|_| HttpResponse::MethodNotAllowed())
/// });
/// .to(|| HttpResponse::MethodNotAllowed())
/// );
/// }
/// ```
pub fn Host<H: AsRef<str>>(host: H) -> HostGuard {

View File

@ -1,25 +1,27 @@
#![deny(rust_2018_idioms, warnings)]
#![allow(clippy::type_complexity, clippy::borrow_interior_mutable_const)]
#![allow(
clippy::needless_doctest_main,
clippy::type_complexity,
clippy::borrow_interior_mutable_const
)]
//! Actix web is a small, pragmatic, and extremely fast web framework
//! for Rust.
//!
//! ```rust
//! ```rust,no_run
//! use actix_web::{web, App, Responder, HttpServer};
//! # use std::thread;
//!
//! async fn index(info: web::Path<(String, u32)>) -> impl Responder {
//! format!("Hello {}! id:{}", info.0, info.1)
//! }
//!
//! fn main() -> std::io::Result<()> {
//! # thread::spawn(|| {
//! #[actix_rt::main]
//! async fn main() -> std::io::Result<()> {
//! HttpServer::new(|| App::new().service(
//! web::resource("/{name}/{id}/index.html").to(index))
//! )
//! .bind("127.0.0.1:8080")?
//! .run()
//! # });
//! # Ok(())
//! .start()
//! .await
//! }
//! ```
//!
@ -170,7 +172,6 @@ pub mod client {
//! An HTTP Client
//!
//! ```rust
//! use actix_rt::System;
//! use actix_web::client::Client;
//!
//! #[actix_rt::main]

View File

@ -140,7 +140,7 @@ where
#[pin]
fut: S::Future,
encoding: ContentEncoding,
_t: PhantomData<(B)>,
_t: PhantomData<B>,
}
impl<S, B> Future for CompressResponse<S, B>
@ -178,6 +178,7 @@ struct AcceptEncoding {
impl Eq for AcceptEncoding {}
impl Ord for AcceptEncoding {
#[allow(clippy::comparison_chain)]
fn cmp(&self, other: &AcceptEncoding) -> cmp::Ordering {
if self.quality > other.quality {
cmp::Ordering::Less

View File

@ -44,13 +44,11 @@ pub use crate::types::*;
/// # extern crate actix_web;
/// use actix_web::{web, App, HttpResponse};
///
/// fn main() {
/// let app = App::new().service(
/// web::resource("/users/{userid}/{friend}")
/// .route(web::get().to(|| HttpResponse::Ok()))
/// .route(web::head().to(|| HttpResponse::MethodNotAllowed()))
/// );
/// }
/// let app = App::new().service(
/// web::resource("/users/{userid}/{friend}")
/// .route(web::get().to(|| HttpResponse::Ok()))
/// .route(web::head().to(|| HttpResponse::MethodNotAllowed()))
/// );
/// ```
pub fn resource(path: &str) -> Resource {
Resource::new(path)
@ -64,14 +62,12 @@ pub fn resource(path: &str) -> Resource {
/// ```rust
/// use actix_web::{web, App, HttpResponse};
///
/// fn main() {
/// let app = App::new().service(
/// web::scope("/{project_id}")
/// .service(web::resource("/path1").to(|| HttpResponse::Ok()))
/// .service(web::resource("/path2").to(|| HttpResponse::Ok()))
/// .service(web::resource("/path3").to(|| HttpResponse::MethodNotAllowed()))
/// );
/// }
/// let app = App::new().service(
/// web::scope("/{project_id}")
/// .service(web::resource("/path1").to(|| HttpResponse::Ok()))
/// .service(web::resource("/path2").to(|| HttpResponse::Ok()))
/// .service(web::resource("/path3").to(|| HttpResponse::MethodNotAllowed()))
/// );
/// ```
///
/// In the above example, three routes get added:
@ -93,12 +89,10 @@ pub fn route() -> Route {
/// ```rust
/// use actix_web::{web, App, HttpResponse};
///
/// fn main() {
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::get().to(|| HttpResponse::Ok()))
/// );
/// }
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::get().to(|| HttpResponse::Ok()))
/// );
/// ```
///
/// In the above example, one `GET` route get added:
@ -113,12 +107,10 @@ pub fn get() -> Route {
/// ```rust
/// use actix_web::{web, App, HttpResponse};
///
/// fn main() {
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::post().to(|| HttpResponse::Ok()))
/// );
/// }
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::post().to(|| HttpResponse::Ok()))
/// );
/// ```
///
/// In the above example, one `POST` route get added:
@ -133,12 +125,10 @@ pub fn post() -> Route {
/// ```rust
/// use actix_web::{web, App, HttpResponse};
///
/// fn main() {
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::put().to(|| HttpResponse::Ok()))
/// );
/// }
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::put().to(|| HttpResponse::Ok()))
/// );
/// ```
///
/// In the above example, one `PUT` route get added:
@ -153,12 +143,10 @@ pub fn put() -> Route {
/// ```rust
/// use actix_web::{web, App, HttpResponse};
///
/// fn main() {
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::patch().to(|| HttpResponse::Ok()))
/// );
/// }
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::patch().to(|| HttpResponse::Ok()))
/// );
/// ```
///
/// In the above example, one `PATCH` route get added:
@ -173,12 +161,10 @@ pub fn patch() -> Route {
/// ```rust
/// use actix_web::{web, App, HttpResponse};
///
/// fn main() {
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::delete().to(|| HttpResponse::Ok()))
/// );
/// }
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::delete().to(|| HttpResponse::Ok()))
/// );
/// ```
///
/// In the above example, one `DELETE` route get added:
@ -193,12 +179,10 @@ pub fn delete() -> Route {
/// ```rust
/// use actix_web::{web, App, HttpResponse};
///
/// fn main() {
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::head().to(|| HttpResponse::Ok()))
/// );
/// }
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::head().to(|| HttpResponse::Ok()))
/// );
/// ```
///
/// In the above example, one `HEAD` route get added:
@ -213,12 +197,10 @@ pub fn head() -> Route {
/// ```rust
/// use actix_web::{web, http, App, HttpResponse};
///
/// fn main() {
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::method(http::Method::GET).to(|| HttpResponse::Ok()))
/// );
/// }
/// let app = App::new().service(
/// web::resource("/{project_id}")
/// .route(web::method(http::Method::GET).to(|| HttpResponse::Ok()))
/// );
/// ```
///
/// In the above example, one `GET` route get added:
@ -261,13 +243,11 @@ where
/// Ok(req.into_response(HttpResponse::Ok().finish()))
/// }
///
/// fn main() {
/// let app = App::new().service(
/// web::service("/users/*")
/// .guard(guard::Header("content-type", "text/plain"))
/// .finish(my_service)
/// );
/// }
/// let app = App::new().service(
/// web::service("/users/*")
/// .guard(guard::Header("content-type", "text/plain"))
/// .finish(my_service)
/// );
/// ```
pub fn service(path: &str) -> WebService {
WebService::new(path)