1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

update doc api examples

This commit is contained in:
Nikolay Kim 2018-06-17 04:09:07 +06:00
parent a7a062fb68
commit 70244c29e0
5 changed files with 26 additions and 50 deletions

View File

@ -1,29 +1,5 @@
## 0.7 ## 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) * [Middleware](https://actix.rs/actix-web/actix_web/middleware/trait.Middleware.html)
trait uses `&mut self` instead of `&self`. trait uses `&mut self` instead of `&self`.

View File

@ -298,7 +298,6 @@ impl ClientConnector {
/// # #![cfg(feature="alpn")] /// # #![cfg(feature="alpn")]
/// # extern crate actix_web; /// # extern crate actix_web;
/// # extern crate futures; /// # extern crate futures;
/// # extern crate tokio;
/// # use futures::{future, Future}; /// # use futures::{future, Future};
/// # use std::io::Write; /// # use std::io::Write;
/// # use std::process; /// # use std::process;
@ -309,11 +308,13 @@ impl ClientConnector {
/// use openssl::ssl::{SslConnector, SslMethod}; /// use openssl::ssl::{SslConnector, SslMethod};
/// ///
/// fn main() { /// fn main() {
/// tokio::run(future::lazy(|| { /// let mut sys = actix_web::actix::System::new("test");
///
/// // Start `ClientConnector` with custom `SslConnector` /// // Start `ClientConnector` with custom `SslConnector`
/// let ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap().build(); /// let ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap().build();
/// let conn = ClientConnector::with_connector(ssl_conn).start(); /// let conn = ClientConnector::with_connector(ssl_conn).start();
/// ///
/// sys.block_on(
/// conn.send( /// conn.send(
/// Connect::new("https://www.rust-lang.org").unwrap()) // <- connect to host /// Connect::new("https://www.rust-lang.org").unwrap()) // <- connect to host
/// .map_err(|_| ()) /// .map_err(|_| ())
@ -321,10 +322,9 @@ impl ClientConnector {
/// if let Ok(mut stream) = res { /// if let Ok(mut stream) = res {
/// stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap(); /// stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();
/// } /// }
/// # process::exit(0);
/// Ok(()) /// Ok(())
/// }) /// })
/// })); /// );
/// } /// }
/// ``` /// ```
pub fn with_connector(connector: SslConnector) -> ClientConnector { pub fn with_connector(connector: SslConnector) -> ClientConnector {

View File

@ -9,7 +9,9 @@
//! use actix_web::client; //! use actix_web::client;
//! //!
//! fn main() { //! 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 //! client::get("http://www.rust-lang.org") // <- Create request builder
//! .header("User-Agent", "Actix-web") //! .header("User-Agent", "Actix-web")
//! .finish().unwrap() //! .finish().unwrap()
@ -17,13 +19,11 @@
//! .map_err(|_| ()) //! .map_err(|_| ())
//! .and_then(|response| { // <- server http response //! .and_then(|response| { // <- server http response
//! println!("Response: {:?}", response); //! println!("Response: {:?}", response);
//! # process::exit(0);
//! Ok(()) //! Ok(())
//! }) //! })
//! }); //! );
//! } //! }
//! ``` //! ```
mod body; mod body;
mod connector; mod connector;
mod parser; mod parser;

View File

@ -46,7 +46,7 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
/// use actix_web::{actix, server, App, HttpResponse}; /// use actix_web::{actix, server, App, HttpResponse};
/// ///
/// fn main() { /// fn main() {
/// actix::System::run(|| { /// let sys = actix::System::new("example"); // <- create Actix system
/// ///
/// server::new( /// server::new(
/// || App::new() /// || App::new()
@ -55,7 +55,7 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
/// .start(); /// .start();
/// ///
/// # actix::System::current().stop(); /// # actix::System::current().stop();
/// }); /// sys.run();
/// } /// }
/// ``` /// ```
pub fn new<F, U, H>(factory: F) -> HttpServer<H> pub fn new<F, U, H>(factory: F) -> HttpServer<H>

View File

@ -402,14 +402,14 @@ impl<H: IntoHttpHandler> HttpServer<H> {
/// use actix_web::{actix, server, App, HttpResponse}; /// use actix_web::{actix, server, App, HttpResponse};
/// ///
/// fn main() { /// fn main() {
/// // Run actix system, this method actually starts all async processes /// let sys = actix::System::new("example"); // <- create Actix system
/// actix::System::run(|| { ///
/// server::new(|| App::new().resource("/", |r| r.h(|_| HttpResponse::Ok()))) /// server::new(|| App::new().resource("/", |r| r.h(|_| HttpResponse::Ok())))
/// .bind("127.0.0.1:0") /// .bind("127.0.0.1:0")
/// .expect("Can not bind to 127.0.0.1:0") /// .expect("Can not bind to 127.0.0.1:0")
/// .start(); /// .start();
/// # actix::System::current().stop(); /// # actix::System::current().stop();
/// }); /// sys.run(); // <- Run actix system, this method starts all async processes
/// } /// }
/// ``` /// ```
pub fn start(mut self) -> Addr<Self> { pub fn start(mut self) -> Addr<Self> {