From 5c42b0902f9cc38b1e6e7c8a53637f1ca781a170 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 19 Jun 2018 12:07:07 +0600 Subject: [PATCH] better doc api examples --- Cargo.toml | 3 ++- src/client/connector.rs | 13 ++++++------- src/client/mod.rs | 18 ++++++++---------- src/client/request.rs | 9 ++++----- src/lib.rs | 1 + 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ad7e1612..61259c79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,8 @@ flate2-rust = ["flate2/rust_backend"] features = ["tls", "alpn", "session", "brotli", "flate2-c"] [dependencies] -actix = "0.6" +actix = "0.6.1" + base64 = "0.9" bitflags = "1.0" failure = "0.1.1" diff --git a/src/client/connector.rs b/src/client/connector.rs index 2727cc12..2d70ff06 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -303,18 +303,16 @@ impl ClientConnector { /// # use std::process; /// # use actix_web::actix::Actor; /// extern crate openssl; - /// use actix_web::client::{ClientConnector, Connect}; + /// use actix_web::{actix, client::ClientConnector, client::Connect}; /// /// use openssl::ssl::{SslConnector, SslMethod}; /// /// fn main() { - /// let mut sys = actix_web::actix::System::new("test"); + /// actix::run(|| { + /// // Start `ClientConnector` with custom `SslConnector` + /// let ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap().build(); + /// let conn = ClientConnector::with_connector(ssl_conn).start(); /// - /// // 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(|_| ()) @@ -322,6 +320,7 @@ impl ClientConnector { /// if let Ok(mut stream) = res { /// stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap(); /// } + /// # actix::System::current().stop(); /// Ok(()) /// }) /// ); diff --git a/src/client/mod.rs b/src/client/mod.rs index bbc2d5f3..5685e093 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -6,19 +6,18 @@ //! # extern crate tokio; //! # use futures::Future; //! # use std::process; -//! use actix_web::client; +//! use actix_web::{actix, client}; //! //! fn main() { -//! let mut sys = actix_web::actix::System::new("test"); -//! -//! sys.block_on( -//! client::get("http://www.rust-lang.org") // <- Create request builder +//! actix::run( +//! || client::get("http://www.rust-lang.org") // <- Create request builder //! .header("User-Agent", "Actix-web") //! .finish().unwrap() //! .send() // <- Send http request //! .map_err(|_| ()) //! .and_then(|response| { // <- server http response //! println!("Response: {:?}", response); +//! # actix::System::current().stop(); //! Ok(()) //! }) //! ); @@ -66,19 +65,18 @@ impl ResponseError for SendRequestError { /// # extern crate env_logger; /// # use futures::Future; /// # use std::process; -/// use actix_web::client; +/// use actix_web::{actix, client}; /// /// fn main() { -/// let mut sys = actix_web::actix::System::new("test"); -/// -/// sys.block_on( -/// client::get("http://www.rust-lang.org") // <- Create request builder +/// actix::run( +/// || client::get("http://www.rust-lang.org") // <- Create request builder /// .header("User-Agent", "Actix-web") /// .finish().unwrap() /// .send() // <- Send http request /// .map_err(|_| ()) /// .and_then(|response| { // <- server http response /// println!("Response: {:?}", response); +/// # actix::System::current().stop(); /// Ok(()) /// }), /// ); diff --git a/src/client/request.rs b/src/client/request.rs index d82aa606..351b4b6d 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -31,19 +31,18 @@ use httprequest::HttpRequest; /// # extern crate tokio; /// # use futures::Future; /// # use std::process; -/// use actix_web::client::ClientRequest; +/// use actix_web::{actix, client}; /// /// fn main() { -/// let mut sys = actix_web::actix::System::new("test"); -/// -/// sys.block_on( -/// ClientRequest::get("http://www.rust-lang.org") // <- Create request builder +/// actix::run( +/// || client::ClientRequest::get("http://www.rust-lang.org") // <- Create request builder /// .header("User-Agent", "Actix-web") /// .finish().unwrap() /// .send() // <- Send http request /// .map_err(|_| ()) /// .and_then(|response| { // <- server http response /// println!("Response: {:?}", response); +/// # actix::System::current().stop(); /// Ok(()) /// }), /// ); diff --git a/src/lib.rs b/src/lib.rs index dc956ac9..95f5a4ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -210,6 +210,7 @@ pub mod actix { pub use self::actix::fut; pub use self::actix::msgs; pub use self::actix::prelude::*; + pub use self::actix::{run, spawn}; } #[cfg(feature = "openssl")]