diff --git a/MIGRATION.md b/MIGRATION.md index 628f0590e..175d82b3c 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -1,29 +1,5 @@ ## 0.7 -* `actix::System` has new api. - - Instead of - - ```rust - fn main() { - let sys = actix::System::new(..); - - HttpServer::new(|| ...).start() - - sys.run(); - } - ``` - - Server must be initialized within system run closure: - - ```rust - fn main() { - actix::System::run(|| { - HttpServer::new(|| ...).start() - }); - } - ``` - * [Middleware](https://actix.rs/actix-web/actix_web/middleware/trait.Middleware.html) trait uses `&mut self` instead of `&self`. diff --git a/src/client/connector.rs b/src/client/connector.rs index 5b8444868..2727cc124 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -298,7 +298,6 @@ impl ClientConnector { /// # #![cfg(feature="alpn")] /// # extern crate actix_web; /// # extern crate futures; - /// # extern crate tokio; /// # use futures::{future, Future}; /// # use std::io::Write; /// # use std::process; @@ -309,11 +308,13 @@ impl ClientConnector { /// use openssl::ssl::{SslConnector, SslMethod}; /// /// fn main() { - /// tokio::run(future::lazy(|| { - /// // Start `ClientConnector` with custom `SslConnector` - /// let ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap().build(); - /// let conn = ClientConnector::with_connector(ssl_conn).start(); + /// let mut sys = actix_web::actix::System::new("test"); /// + /// // Start `ClientConnector` with custom `SslConnector` + /// let ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap().build(); + /// let conn = ClientConnector::with_connector(ssl_conn).start(); + /// + /// sys.block_on( /// conn.send( /// Connect::new("https://www.rust-lang.org").unwrap()) // <- connect to host /// .map_err(|_| ()) @@ -321,10 +322,9 @@ impl ClientConnector { /// if let Ok(mut stream) = res { /// stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap(); /// } - /// # process::exit(0); /// Ok(()) /// }) - /// })); + /// ); /// } /// ``` pub fn with_connector(connector: SslConnector) -> ClientConnector { diff --git a/src/client/mod.rs b/src/client/mod.rs index 3c9567333..b40fa2ece 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -9,7 +9,9 @@ //! use actix_web::client; //! //! fn main() { -//! tokio::run({ +//! let mut sys = actix_web::actix::System::new("test"); +//! +//! sys.block_on( //! client::get("http://www.rust-lang.org") // <- Create request builder //! .header("User-Agent", "Actix-web") //! .finish().unwrap() @@ -17,13 +19,11 @@ //! .map_err(|_| ()) //! .and_then(|response| { // <- server http response //! println!("Response: {:?}", response); -//! # process::exit(0); //! Ok(()) //! }) -//! }); +//! ); //! } //! ``` - mod body; mod connector; mod parser; diff --git a/src/server/mod.rs b/src/server/mod.rs index 0c27d55ea..978454abd 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -46,16 +46,16 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536; /// use actix_web::{actix, server, App, HttpResponse}; /// /// fn main() { -/// actix::System::run(|| { +/// let sys = actix::System::new("example"); // <- create Actix system /// -/// server::new( -/// || App::new() -/// .resource("/", |r| r.f(|_| HttpResponse::Ok()))) -/// .bind("127.0.0.1:59090").unwrap() -/// .start(); +/// server::new( +/// || App::new() +/// .resource("/", |r| r.f(|_| HttpResponse::Ok()))) +/// .bind("127.0.0.1:59090").unwrap() +/// .start(); /// /// # actix::System::current().stop(); -/// }); +/// sys.run(); /// } /// ``` pub fn new(factory: F) -> HttpServer diff --git a/src/server/srv.rs b/src/server/srv.rs index 897dbb09d..0e51e2dc3 100644 --- a/src/server/srv.rs +++ b/src/server/srv.rs @@ -402,14 +402,14 @@ impl HttpServer { /// use actix_web::{actix, server, App, HttpResponse}; /// /// fn main() { - /// // Run actix system, this method actually starts all async processes - /// actix::System::run(|| { - /// server::new(|| App::new().resource("/", |r| r.h(|_| HttpResponse::Ok()))) - /// .bind("127.0.0.1:0") - /// .expect("Can not bind to 127.0.0.1:0") - /// .start(); - /// # actix::System::current().stop(); - /// }); + /// let sys = actix::System::new("example"); // <- create Actix system + /// + /// server::new(|| App::new().resource("/", |r| r.h(|_| HttpResponse::Ok()))) + /// .bind("127.0.0.1:0") + /// .expect("Can not bind to 127.0.0.1:0") + /// .start(); + /// # actix::System::current().stop(); + /// sys.run(); // <- Run actix system, this method starts all async processes /// } /// ``` pub fn start(mut self) -> Addr {