1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 23:51:06 +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
* `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`.

View File

@ -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 {

View File

@ -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;

View File

@ -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<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};
///
/// 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<Self> {