Skip to content

Commit

Permalink
update tests and clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Dec 8, 2019
1 parent 6c9f9ff commit 4a8a9ef
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 201 deletions.
10 changes: 0 additions & 10 deletions actix-http/src/cookie/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ use super::{Cookie, SameSite};
/// ```rust
/// use actix_http::cookie::Cookie;
///
/// # fn main() {
/// let cookie: Cookie = Cookie::build("name", "value")
/// .domain("www.rust-lang.org")
/// .path("/")
/// .secure(true)
/// .http_only(true)
/// .max_age(84600)
/// .finish();
/// # }
/// ```
#[derive(Debug, Clone)]
pub struct CookieBuilder {
Expand Down Expand Up @@ -65,13 +63,11 @@ impl CookieBuilder {
/// ```rust
/// use actix_http::cookie::Cookie;
///
/// # fn main() {
/// let c = Cookie::build("foo", "bar")
/// .expires(time::now())
/// .finish();
///
/// assert!(c.expires().is_some());
/// # }
/// ```
#[inline]
pub fn expires(mut self, when: Tm) -> CookieBuilder {
Expand All @@ -86,13 +82,11 @@ impl CookieBuilder {
/// ```rust
/// use actix_http::cookie::Cookie;
///
/// # fn main() {
/// let c = Cookie::build("foo", "bar")
/// .max_age(1800)
/// .finish();
///
/// assert_eq!(c.max_age(), Some(time::Duration::seconds(30 * 60)));
/// # }
/// ```
#[inline]
pub fn max_age(self, seconds: i64) -> CookieBuilder {
Expand All @@ -106,13 +100,11 @@ impl CookieBuilder {
/// ```rust
/// use actix_http::cookie::Cookie;
///
/// # fn main() {
/// let c = Cookie::build("foo", "bar")
/// .max_age_time(time::Duration::minutes(30))
/// .finish();
///
/// assert_eq!(c.max_age(), Some(time::Duration::seconds(30 * 60)));
/// # }
/// ```
#[inline]
pub fn max_age_time(mut self, value: Duration) -> CookieBuilder {
Expand Down Expand Up @@ -222,14 +214,12 @@ impl CookieBuilder {
/// use actix_http::cookie::Cookie;
/// use chrono::Duration;
///
/// # fn main() {
/// let c = Cookie::build("foo", "bar")
/// .permanent()
/// .finish();
///
/// assert_eq!(c.max_age(), Some(Duration::days(365 * 20)));
/// # assert!(c.expires().is_some());
/// # }
/// ```
#[inline]
pub fn permanent(mut self) -> CookieBuilder {
Expand Down
4 changes: 0 additions & 4 deletions actix-http/src/cookie/jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ impl CookieJar {
/// use actix_http::cookie::{CookieJar, Cookie};
/// use chrono::Duration;
///
/// # fn main() {
/// let mut jar = CookieJar::new();
///
/// // Assume this cookie originally had a path of "/" and domain of "a.b".
Expand All @@ -204,7 +203,6 @@ impl CookieJar {
/// assert_eq!(delta.len(), 1);
/// assert_eq!(delta[0].name(), "name");
/// assert_eq!(delta[0].max_age(), Some(Duration::seconds(0)));
/// # }
/// ```
///
/// Removing a new cookie does not result in a _removal_ cookie:
Expand Down Expand Up @@ -243,7 +241,6 @@ impl CookieJar {
/// use actix_http::cookie::{CookieJar, Cookie};
/// use chrono::Duration;
///
/// # fn main() {
/// let mut jar = CookieJar::new();
///
/// // Add an original cookie and a new cookie.
Expand All @@ -261,7 +258,6 @@ impl CookieJar {
/// jar.force_remove(Cookie::new("key", "value"));
/// assert_eq!(jar.delta().count(), 0);
/// assert_eq!(jar.iter().count(), 0);
/// # }
/// ```
pub fn force_remove<'a>(&mut self, cookie: Cookie<'a>) {
self.original_cookies.remove(cookie.name());
Expand Down
6 changes: 0 additions & 6 deletions actix-http/src/cookie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,11 @@ impl<'c> Cookie<'c> {
/// use actix_http::cookie::Cookie;
/// use chrono::Duration;
///
/// # fn main() {
/// let mut c = Cookie::new("name", "value");
/// assert_eq!(c.max_age(), None);
///
/// c.set_max_age(Duration::hours(10));
/// assert_eq!(c.max_age(), Some(Duration::hours(10)));
/// # }
/// ```
#[inline]
pub fn set_max_age(&mut self, value: Duration) {
Expand Down Expand Up @@ -701,7 +699,6 @@ impl<'c> Cookie<'c> {
/// ```rust
/// use actix_http::cookie::Cookie;
///
/// # fn main() {
/// let mut c = Cookie::new("name", "value");
/// assert_eq!(c.expires(), None);
///
Expand All @@ -710,7 +707,6 @@ impl<'c> Cookie<'c> {
///
/// c.set_expires(now);
/// assert!(c.expires().is_some())
/// # }
/// ```
#[inline]
pub fn set_expires(&mut self, time: Tm) {
Expand All @@ -726,15 +722,13 @@ impl<'c> Cookie<'c> {
/// use actix_http::cookie::Cookie;
/// use chrono::Duration;
///
/// # fn main() {
/// let mut c = Cookie::new("foo", "bar");
/// assert!(c.expires().is_none());
/// assert!(c.max_age().is_none());
///
/// c.make_permanent();
/// assert!(c.expires().is_some());
/// assert_eq!(c.max_age(), Some(Duration::days(365 * 20)));
/// # }
/// ```
pub fn make_permanent(&mut self) {
let twenty_years = Duration::days(365 * 20);
Expand Down
2 changes: 0 additions & 2 deletions actix-http/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,12 @@ impl ResponseError for ContentTypeError {
/// default.
///
/// ```rust
/// # extern crate actix_http;
/// # use std::io;
/// # use actix_http::*;
///
/// fn index(req: Request) -> Result<&'static str> {
/// Err(error::ErrorBadRequest(io::Error::new(io::ErrorKind::Other, "error")))
/// }
/// # fn main() {}
/// ```
pub struct InternalError<T> {
cause: T,
Expand Down
3 changes: 0 additions & 3 deletions actix-http/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ impl ResponseBuilder {
/// ))
/// .finish())
/// }
/// fn main() {}
/// ```
#[doc(hidden)]
pub fn set<H: Header>(&mut self, hdr: H) -> &mut Self {
Expand All @@ -380,7 +379,6 @@ impl ResponseBuilder {
/// .header(http::header::CONTENT_TYPE, "application/json")
/// .finish()
/// }
/// fn main() {}
/// ```
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Self
where
Expand Down Expand Up @@ -413,7 +411,6 @@ impl ResponseBuilder {
/// .set_header(http::header::CONTENT_TYPE, "application/json")
/// .finish()
/// }
/// fn main() {}
/// ```
pub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut Self
where
Expand Down
16 changes: 6 additions & 10 deletions actix-http/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use crate::Request;
/// Test `Request` builder
///
/// ```rust,ignore
/// # extern crate http;
/// # extern crate actix_web;
/// # use http::{header, StatusCode};
/// # use actix_web::*;
/// use actix_web::test::TestRequest;
Expand All @@ -35,15 +33,13 @@ use crate::Request;
/// }
/// }
///
/// fn main() {
/// let resp = TestRequest::with_header("content-type", "text/plain")
/// .run(&index)
/// .unwrap();
/// assert_eq!(resp.status(), StatusCode::OK);
/// let resp = TestRequest::with_header("content-type", "text/plain")
/// .run(&index)
/// .unwrap();
/// assert_eq!(resp.status(), StatusCode::OK);
///
/// let resp = TestRequest::default().run(&index).unwrap();
/// assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
/// }
/// let resp = TestRequest::default().run(&index).unwrap();
/// assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
/// ```
pub struct TestRequest(Option<Inner>);

Expand Down
11 changes: 5 additions & 6 deletions actix-session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! [*Session*](struct.Session.html) extractor must be used. Session
//! extractor allows us to get or set session data.
//!
//! ```rust
//! ```rust,no_run
//! use actix_web::{web, App, HttpServer, HttpResponse, Error};
//! use actix_session::{Session, CookieSession};
//!
Expand All @@ -28,18 +28,17 @@
//! Ok("Welcome!")
//! }
//!
//! fn main() -> std::io::Result<()> {
//! # std::thread::spawn(||
//! #[actix_rt::main]
//! async fn main() -> std::io::Result<()> {
//! HttpServer::new(
//! || App::new().wrap(
//! CookieSession::signed(&[0; 32]) // <- create cookie based session middleware
//! .secure(false)
//! )
//! .service(web::resource("/").to(|| HttpResponse::Ok())))
//! .bind("127.0.0.1:59880")?
//! .run()
//! # );
//! # Ok(())
//! .start()
//! .await
//! }
//! ```
use std::cell::RefCell;
Expand Down
4 changes: 2 additions & 2 deletions actix-web-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ proc-macro2 = "^1"
[dev-dependencies]
actix-rt = { version = "1.0.0-alpha.2" }
actix-web = { version = "2.0.0-alpha.2" }
actix-http = { version = "0.3.0-alpha.2", features=["openssl"] }
actix-http-test = { version = "0.3.0-alpha.2", features=["openssl"] }
actix-http = { version = "1.0.0-alpha.3", features=["openssl"] }
actix-http-test = { version = "1.0.0-alpha.3", features=["openssl"] }
futures = { version = "0.3.1" }
2 changes: 1 addition & 1 deletion awc/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<T: AsyncRead + AsyncWrite + Unpin> AsyncSocket for Socket<T> {
pub struct BoxedSocket(Box<dyn AsyncSocket>);

impl fmt::Debug for BoxedSocket {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "BoxedSocket")
}
}
Expand Down
35 changes: 18 additions & 17 deletions awc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![allow(clippy::borrow_interior_mutable_const)]
#![deny(rust_2018_idioms, warnings)]
#![allow(
clippy::type_complexity,
clippy::borrow_interior_mutable_const,
clippy::needless_doctest_main
)]
//! An HTTP Client
//!
//! ```rust
Expand All @@ -11,9 +16,9 @@
//! let mut client = Client::default();
//!
//! let response = client.get("http://www.rust-lang.org") // <- Create request builder
//! .header("User-Agent", "Actix-web")
//! .send() // <- Send http request
//! .await;
//! .header("User-Agent", "Actix-web")
//! .send() // <- Send http request
//! .await;
//!
//! println!("Response: {:?}", response);
//! }
Expand Down Expand Up @@ -50,22 +55,18 @@ use self::connect::{Connect, ConnectorWrapper};
/// An HTTP Client
///
/// ```rust
/// use actix_rt::System;
/// use awc::Client;
///
/// fn main() {
/// System::new("test").block_on(async {
/// let mut client = Client::default();
/// #[actix_rt::main]
/// async fn main() {
/// let mut client = Client::default();
///
/// client.get("http://www.rust-lang.org") // <- Create request builder
/// .header("User-Agent", "Actix-web")
/// .send() // <- Send http request
/// .await
/// .and_then(|response| { // <- server http response
/// println!("Response: {:?}", response);
/// Ok(())
/// })
/// });
/// let res = client.get("http://www.rust-lang.org") // <- Create request builder
/// .header("User-Agent", "Actix-web")
/// .send() // <- Send http request
/// .await; // <- send request and wait for response
///
/// println!("Response: {:?}", res);
/// }
/// ```
#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion awc/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ impl ClientRequest {
}

impl fmt::Debug for ClientRequest {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(
f,
"\nClientRequest {:?} {}:{}",
Expand Down
Loading

0 comments on commit 4a8a9ef

Please sign in to comment.