From 2dafd9c6814904c2bd2e968fefb844343de76d1e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 6 Apr 2018 08:40:11 -0700 Subject: [PATCH] do not re-export HttpServer from server module --- examples/basics/src/main.rs | 6 +++--- examples/http-proxy/src/main.rs | 9 +++++---- examples/json/src/main.rs | 2 +- examples/juniper/src/main.rs | 2 +- examples/multipart/src/main.rs | 2 +- examples/protobuf/src/main.rs | 2 +- examples/r2d2/src/main.rs | 2 +- examples/state/src/main.rs | 4 ++-- examples/template_tera/src/main.rs | 4 ++-- examples/tls/src/main.rs | 2 +- examples/unix-socket/src/main.rs | 4 ++-- examples/websocket-chat/src/main.rs | 4 ++-- examples/websocket/src/main.rs | 2 +- guide/src/qs_10.md | 4 ++-- guide/src/qs_2.md | 4 ++-- guide/src/qs_3.md | 4 ++-- guide/src/qs_3_5.md | 14 ++++++-------- guide/src/qs_4.md | 4 ++-- src/client/connector.rs | 12 ++++++------ src/lib.rs | 1 - src/server/mod.rs | 6 ++++-- 21 files changed, 47 insertions(+), 47 deletions(-) diff --git a/examples/basics/src/main.rs b/examples/basics/src/main.rs index 750fc7640..cfc9933db 100644 --- a/examples/basics/src/main.rs +++ b/examples/basics/src/main.rs @@ -8,8 +8,8 @@ extern crate futures; use futures::Stream; use std::{io, env}; -use actix_web::{error, fs, pred, - App, HttpRequest, HttpResponse, HttpServer, Result, Error}; +use actix_web::{error, fs, pred, server, + App, HttpRequest, HttpResponse, Result, Error}; use actix_web::http::{Method, StatusCode}; use actix_web::middleware::{self, RequestSession}; use futures::future::{FutureResult, result}; @@ -99,7 +99,7 @@ fn main() { env_logger::init(); let sys = actix::System::new("basic-example"); - let addr = HttpServer::new( + let addr = server::new( || App::new() // enable logger .middleware(middleware::Logger::default()) diff --git a/examples/http-proxy/src/main.rs b/examples/http-proxy/src/main.rs index a69fff88d..0a392ed8a 100644 --- a/examples/http-proxy/src/main.rs +++ b/examples/http-proxy/src/main.rs @@ -4,9 +4,10 @@ extern crate futures; extern crate env_logger; use futures::{Future, Stream}; -use actix_web::{client, server, middleware, - App, AsyncResponder, Body, - HttpRequest, HttpResponse, HttpMessage, Error}; +use actix_web::{ + client, server, middleware, + App, AsyncResponder, Body, HttpRequest, HttpResponse, HttpMessage, Error}; + /// Stream client request response and then send body to a server response fn index(_req: HttpRequest) -> Box> { @@ -44,7 +45,7 @@ fn main() { env_logger::init(); let sys = actix::System::new("http-proxy"); - let _addr = server::new( + server::new( || App::new() .middleware(middleware::Logger::default()) .resource("/streaming", |r| r.f(streaming)) diff --git a/examples/json/src/main.rs b/examples/json/src/main.rs index 73863eefd..f864e0083 100644 --- a/examples/json/src/main.rs +++ b/examples/json/src/main.rs @@ -89,7 +89,7 @@ fn main() { env_logger::init(); let sys = actix::System::new("json-example"); - let _ = server::new(|| { + server::new(|| { App::new() // enable logger .middleware(middleware::Logger::default()) diff --git a/examples/juniper/src/main.rs b/examples/juniper/src/main.rs index 11676505d..a92ce3fb7 100644 --- a/examples/juniper/src/main.rs +++ b/examples/juniper/src/main.rs @@ -94,7 +94,7 @@ fn main() { }); // Start http server - let _ = server::new(move || { + server::new(move || { App::with_state(AppState{executor: addr.clone()}) // enable logger .middleware(middleware::Logger::default()) diff --git a/examples/multipart/src/main.rs b/examples/multipart/src/main.rs index cac76d30c..75f28963f 100644 --- a/examples/multipart/src/main.rs +++ b/examples/multipart/src/main.rs @@ -49,7 +49,7 @@ fn main() { let _ = env_logger::init(); let sys = actix::System::new("multipart-example"); - let _ = server::new( + server::new( || App::new() .middleware(middleware::Logger::default()) // <- logger .resource("/multipart", |r| r.method(http::Method::POST).a(index))) diff --git a/examples/protobuf/src/main.rs b/examples/protobuf/src/main.rs index ae61e0e46..c0a2abb3a 100644 --- a/examples/protobuf/src/main.rs +++ b/examples/protobuf/src/main.rs @@ -44,7 +44,7 @@ fn main() { env_logger::init(); let sys = actix::System::new("protobuf-example"); - let _ = server::new(|| { + server::new(|| { App::new() .middleware(middleware::Logger::default()) .resource("/", |r| r.method(http::Method::POST).f(index))}) diff --git a/examples/r2d2/src/main.rs b/examples/r2d2/src/main.rs index a3cf637c7..5e6d07f81 100644 --- a/examples/r2d2/src/main.rs +++ b/examples/r2d2/src/main.rs @@ -53,7 +53,7 @@ fn main() { let addr = SyncArbiter::start(3, move || DbExecutor(pool.clone())); // Start http server - let _ = server::new(move || { + server::new(move || { App::with_state(State{db: addr.clone()}) // enable logger .middleware(middleware::Logger::default()) diff --git a/examples/state/src/main.rs b/examples/state/src/main.rs index e3b0890bd..804b68c69 100644 --- a/examples/state/src/main.rs +++ b/examples/state/src/main.rs @@ -55,10 +55,10 @@ impl StreamHandler for MyWebSocket { fn main() { ::std::env::set_var("RUST_LOG", "actix_web=info"); - let _ = env_logger::init(); + env_logger::init(); let sys = actix::System::new("ws-example"); - let _ = server::new( + server::new( || App::with_state(AppState{counter: Cell::new(0)}) // enable logger .middleware(middleware::Logger::default()) diff --git a/examples/template_tera/src/main.rs b/examples/template_tera/src/main.rs index fb512d2c4..e1a738d3b 100644 --- a/examples/template_tera/src/main.rs +++ b/examples/template_tera/src/main.rs @@ -30,10 +30,10 @@ fn index(req: HttpRequest) -> Result { fn main() { ::std::env::set_var("RUST_LOG", "actix_web=info"); - let _ = env_logger::init(); + env_logger::init(); let sys = actix::System::new("tera-example"); - let _ = server::new(|| { + server::new(|| { let tera = compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")); App::with_state(State{template: tera}) diff --git a/examples/tls/src/main.rs b/examples/tls/src/main.rs index 809af1716..479ef8c06 100644 --- a/examples/tls/src/main.rs +++ b/examples/tls/src/main.rs @@ -29,7 +29,7 @@ fn main() { builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap(); builder.set_certificate_chain_file("cert.pem").unwrap(); - let _ = server::new( + server::new( || App::new() // enable logger .middleware(middleware::Logger::default()) diff --git a/examples/unix-socket/src/main.rs b/examples/unix-socket/src/main.rs index aeb749d10..c30718472 100644 --- a/examples/unix-socket/src/main.rs +++ b/examples/unix-socket/src/main.rs @@ -4,7 +4,7 @@ extern crate env_logger; extern crate tokio_uds; use actix::*; -use actix_web::*; +use actix_web::{middleware, server, App, HttpRequest}; use tokio_uds::UnixListener; @@ -19,7 +19,7 @@ fn main() { let listener = UnixListener::bind( "/tmp/actix-uds.socket", Arbiter::handle()).expect("bind failed"); - HttpServer::new( + server::new( || App::new() // enable logger .middleware(middleware::Logger::default()) diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index 1de3900c4..d9b495c98 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -17,7 +17,7 @@ extern crate actix_web; use std::time::Instant; use actix::*; -use actix_web::{http, fs, ws, App, HttpRequest, HttpResponse, HttpServer, Error}; +use actix_web::{http, fs, ws, server::HttpServer, App, HttpRequest, HttpResponse, Error}; mod codec; mod server; @@ -183,7 +183,7 @@ fn main() { })); // Create Http server with websocket support - let addr = HttpServer::new( + HttpServer::new( move || { // Websocket sessions state let state = WsChatSessionState { addr: server.clone() }; diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs index bcf2ee7ba..07ad7ff46 100644 --- a/examples/websocket/src/main.rs +++ b/examples/websocket/src/main.rs @@ -45,7 +45,7 @@ impl StreamHandler for MyWebSocket { fn main() { ::std::env::set_var("RUST_LOG", "actix_web=info"); - let _ = env_logger::init(); + env_logger::init(); let sys = actix::System::new("ws-example"); server::new( diff --git a/guide/src/qs_10.md b/guide/src/qs_10.md index aaff39ae1..ce1ed4a7e 100644 --- a/guide/src/qs_10.md +++ b/guide/src/qs_10.md @@ -179,7 +179,7 @@ session data. ```rust # extern crate actix; # extern crate actix_web; -use actix_web::*; +use actix_web::{server, App, HttpRequest, Result}; use actix_web::middleware::{RequestSession, SessionStorage, CookieSessionBackend}; fn index(mut req: HttpRequest) -> Result<&'static str> { @@ -196,7 +196,7 @@ fn index(mut req: HttpRequest) -> Result<&'static str> { fn main() { # let sys = actix::System::new("basic-example"); - HttpServer::new( + server::new( || App::new() .middleware(SessionStorage::new( // <- create session middleware CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend diff --git a/guide/src/qs_2.md b/guide/src/qs_2.md index 543347ccc..91fa8ec8b 100644 --- a/guide/src/qs_2.md +++ b/guide/src/qs_2.md @@ -69,7 +69,7 @@ The full source of src/main.rs is listed below: ```rust # use std::thread; extern crate actix_web; -use actix_web::{App, HttpRequest, HttpResponse, HttpServer}; +use actix_web::{server, App, HttpRequest, HttpResponse}; fn index(req: HttpRequest) -> &'static str { "Hello world!" @@ -80,7 +80,7 @@ fn main() { # // If copying this example in show-all mode, make sure you skip the thread spawn # // call. # thread::spawn(|| { - HttpServer::new( + server::HttpServer::new( || App::new() .resource("/", |r| r.f(index))) .bind("127.0.0.1:8088").expect("Can not bind to 127.0.0.1:8088") diff --git a/guide/src/qs_3.md b/guide/src/qs_3.md index 32cd6bfb4..d5c0b3258 100644 --- a/guide/src/qs_3.md +++ b/guide/src/qs_3.md @@ -45,10 +45,10 @@ Multiple applications can be served with one server: # extern crate tokio_core; # use tokio_core::net::TcpStream; # use std::net::SocketAddr; -use actix_web::{App, HttpResponse, HttpServer}; +use actix_web::{server, App, HttpResponse}; fn main() { - HttpServer::new(|| vec![ + server::new(|| vec![ App::new() .prefix("/app1") .resource("/", |r| r.f(|r| HttpResponse::Ok())), diff --git a/guide/src/qs_3_5.md b/guide/src/qs_3_5.md index 65d8ed71f..82e83ff1d 100644 --- a/guide/src/qs_3_5.md +++ b/guide/src/qs_3_5.md @@ -1,6 +1,6 @@ # Server -The [**HttpServer**](../actix_web/struct.HttpServer.html) type is responsible for +The [**HttpServer**](../actix_web/server/struct.HttpServer.html) type is responsible for serving http requests. `HttpServer` accepts an application factory as a parameter, and the @@ -18,13 +18,12 @@ To start the http server, one of the start methods. ```rust # extern crate actix; # extern crate actix_web; -use actix::*; -use actix_web::{server, App, HttpResponse}; +use actix_web::{server::HttpServer, App, HttpResponse}; fn main() { let sys = actix::System::new("guide"); - server::new( + HttpServer::new( || App::new() .resource("/", |r| r.f(|_| HttpResponse::Ok()))) .bind("127.0.0.1:59080").unwrap() @@ -54,8 +53,7 @@ address of the started http server. It accepts several messages: # use futures::Future; use std::thread; use std::sync::mpsc; -use actix::*; -use actix_web::{server, App, HttpResponse, HttpServer}; +use actix_web::{server, App, HttpResponse}; fn main() { let (tx, rx) = mpsc::channel(); @@ -87,7 +85,7 @@ can be overridden with the `HttpServer::threads()` method. ```rust # extern crate actix_web; # extern crate tokio_core; -use actix_web::{App, HttpServer, HttpResponse}; +use actix_web::{App, HttpResponse, server::HttpServer}; fn main() { HttpServer::new( @@ -123,7 +121,7 @@ fn main() { builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap(); builder.set_certificate_chain_file("cert.pem").unwrap(); - HttpServer::new( + server::new( || App::new() .resource("/index.html", |r| r.f(index))) .bind("127.0.0.1:8080").unwrap() diff --git a/guide/src/qs_4.md b/guide/src/qs_4.md index 582f72568..1a1ff6178 100644 --- a/guide/src/qs_4.md +++ b/guide/src/qs_4.md @@ -130,7 +130,7 @@ Let's create a response for a custom type that serializes to an `application/jso extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; -use actix_web::{App, HttpServer, HttpRequest, HttpResponse, Error, Responder, http}; +use actix_web::{server, App, HttpRequest, HttpResponse, Error, Responder, http}; #[derive(Serialize)] struct MyObj { @@ -160,7 +160,7 @@ fn index(req: HttpRequest) -> MyObj { fn main() { let sys = actix::System::new("example"); - HttpServer::new( + server::new( || App::new() .resource("/", |r| r.method(http::Method::GET).f(index))) .bind("127.0.0.1:8088").unwrap() diff --git a/src/client/connector.rs b/src/client/connector.rs index effee7fa7..85ecd22ba 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -162,7 +162,7 @@ impl ArbiterService for ClientConnector {} impl Default for ClientConnector { fn default() -> ClientConnector { - let modified = Rc::new(Cell::new(false)); + let _modified = Rc::new(Cell::new(false)); #[cfg(all(feature="alpn"))] { @@ -173,8 +173,8 @@ impl Default for ClientConnector { { let builder = TlsConnector::builder().unwrap(); ClientConnector { - pool: Rc::new(Pool::new(Rc::clone(&modified))), - pool_modified: modified, + pool: Rc::new(Pool::new(Rc::clone(&_modified))), + pool_modified: _modified, connector: builder.build().unwrap(), conn_lifetime: Duration::from_secs(15), conn_keep_alive: Duration::from_secs(75), @@ -190,8 +190,8 @@ impl Default for ClientConnector { } #[cfg(not(any(feature="alpn", feature="tls")))] - ClientConnector {pool: Rc::new(Pool::new(Rc::clone(&modified))), - pool_modified: modified, + ClientConnector {pool: Rc::new(Pool::new(Rc::clone(&_modified))), + pool_modified: _modified, conn_lifetime: Duration::from_secs(15), conn_keep_alive: Duration::from_secs(75), limit: 100, @@ -459,7 +459,7 @@ impl ClientConnector { let now = Instant::now(); let mut next = None; - for (_, waiters) in &mut self.waiters { + for waiters in self.waiters.values_mut() { let mut idx = 0; while idx < waiters.len() { if waiters[idx].wait <= now { diff --git a/src/lib.rs b/src/lib.rs index 3e21b3973..f0aef5cc7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,7 +145,6 @@ pub use httprequest::HttpRequest; pub use httpresponse::HttpResponse; pub use handler::{Either, Responder, AsyncResponder, FromRequest, FutureResponse, State}; pub use context::HttpContext; -pub use server::HttpServer; #[doc(hidden)] pub mod httpcodes; diff --git a/src/server/mod.rs b/src/server/mod.rs index 96f53c5ff..bbaa7f744 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -32,7 +32,9 @@ use httpresponse::HttpResponse; /// max buffer size 64k pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536; -/// Create new http server with application factory +/// Create new http server with application factory. +/// +/// This is shortcut for `server::HttpServer::new()` method. /// /// ```rust /// # extern crate actix; @@ -46,7 +48,7 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536; /// server::new( /// || App::new() /// .resource("/", |r| r.f(|_| HttpResponse::Ok()))) -/// .bind("127.0.0.1:59080").unwrap() +/// .bind("127.0.0.1:59090").unwrap() /// .start(); /// /// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));