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

better actix mod re-exports

This commit is contained in:
Nikolay Kim 2018-06-01 09:36:16 -07:00
parent 80965d7a9a
commit 154cd3c5de
11 changed files with 74 additions and 97 deletions

View File

@ -1,16 +1,12 @@
extern crate actix;
use std::collections::{HashMap, VecDeque};
use std::net::Shutdown;
use std::time::{Duration, Instant};
use std::{fmt, io, mem, time};
use self::actix::actors::{Connect as ResolveConnect, Connector, ConnectorError};
use self::actix::fut::WrapFuture;
use self::actix::registry::SystemService;
use self::actix::{
use actix::resolver::{Connect as ResolveConnect, Connector, ConnectorError};
use actix::{
fut, Actor, ActorFuture, ActorResponse, AsyncContext, Context, ContextFutureSpawner,
Handler, Message, Recipient, StreamHandler, Supervised,
Handler, Message, Recipient, StreamHandler, Supervised, SystemService, WrapFuture,
};
use futures::sync::{mpsc, oneshot};
@ -287,7 +283,6 @@ impl ClientConnector {
///
/// ```rust
/// # #![cfg(feature="alpn")]
/// # extern crate actix;
/// # extern crate actix_web;
/// # extern crate futures;
/// # extern crate tokio;
@ -295,14 +290,12 @@ impl ClientConnector {
/// # use std::io::Write;
/// # use std::process;
/// extern crate openssl;
/// use actix::prelude::*;
/// use actix_web::client::{Connect, ClientConnector};
/// use actix_web::client::{ClientConnector, Connect};
///
/// use openssl::ssl::{SslMethod, SslConnector};
/// 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();

View File

@ -1,5 +1,3 @@
extern crate actix;
use bytes::{Bytes, BytesMut};
use futures::sync::oneshot;
use futures::{Async, Future, Poll};
@ -8,7 +6,7 @@ use std::time::{Duration, Instant};
use std::{io, mem};
use tokio_timer::Delay;
use self::actix::prelude::*;
use actix::{Addr, Request, SystemService};
use super::{
ClientBody, ClientBodyStream, ClientConnector, ClientConnectorError, ClientRequest,
@ -56,7 +54,7 @@ impl From<ClientConnectorError> for SendRequestError {
enum State {
New,
Connect(actix::dev::Request<ClientConnector, Connect>),
Connect(Request<ClientConnector, Connect>),
Connection(Connection),
Send(Box<Pipeline>),
None,

View File

@ -118,10 +118,11 @@ pub trait HttpMessage {
/// # extern crate actix_web;
/// # extern crate futures;
/// # #[macro_use] extern crate serde_derive;
/// use actix_web::{
/// AsyncResponder, FutureResponse, HttpMessage, HttpRequest, HttpResponse,
/// };
/// use bytes::Bytes;
/// use futures::future::Future;
/// use actix_web::{HttpMessage, HttpRequest, HttpResponse,
/// FutureResponse, AsyncResponder};
///
/// fn index(mut req: HttpRequest) -> FutureResponse<HttpResponse> {
/// req.body() // <- get Body future
@ -158,7 +159,7 @@ pub trait HttpMessage {
/// # extern crate futures;
/// # use futures::Future;
/// # use std::collections::HashMap;
/// use actix_web::{HttpMessage, HttpRequest, HttpResponse, FutureResponse};
/// use actix_web::{FutureResponse, HttpMessage, HttpRequest, HttpResponse};
///
/// fn index(mut req: HttpRequest) -> FutureResponse<HttpResponse> {
/// Box::new(
@ -167,7 +168,8 @@ pub trait HttpMessage {
/// .and_then(|params| { // <- url encoded parameters
/// println!("==== BODY ==== {:?}", params);
/// Ok(HttpResponse::Ok().into())
/// }))
/// }),
/// )
/// }
/// # fn main() {}
/// ```
@ -193,7 +195,7 @@ pub trait HttpMessage {
/// # extern crate futures;
/// # #[macro_use] extern crate serde_derive;
/// use actix_web::*;
/// use futures::future::{Future, ok};
/// use futures::future::{ok, Future};
///
/// #[derive(Deserialize, Debug)]
/// struct MyObj {
@ -224,13 +226,12 @@ pub trait HttpMessage {
/// ## Server example
///
/// ```rust
/// # extern crate actix;
/// # extern crate actix_web;
/// # extern crate env_logger;
/// # extern crate futures;
/// # use std::str;
/// # use actix_web::*;
/// # use actix::*;
/// # use actix_web::actix::*;
/// # use futures::{Future, Stream};
/// # use futures::future::{ok, result, Either};
/// fn index(mut req: HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {

View File

@ -10,13 +10,13 @@
//! }
//!
//! fn main() {
//! # thread::spawn(|| {
//! server::new(
//! || App::new()
//! .resource("/{name}/{id}/index.html", |r| r.with(index)))
//! .bind("127.0.0.1:8080").unwrap()
//! //#### # thread::spawn(|| {
//! server::new(|| {
//! App::new().resource("/{name}/{id}/index.html", |r| r.with(index))
//! }).bind("127.0.0.1:8080")
//! .unwrap()
//! .run();
//! # });
//! //#### # });
//! }
//! ```
//!
@ -198,13 +198,13 @@ pub use scope::Scope;
pub mod actix {
//! Re-exports [actix's](https://docs.rs/actix) prelude
pub use actix_inner::actors::resolver;
pub use actix_inner::actors::signal;
pub use actix_inner::fut;
pub use actix_inner::msgs;
pub use actix_inner::prelude::*;
}
#[doc(hidden)]
#[deprecated(since = "0.6.2", note = "please use `use actix_web::ws::WsWriter`")]
pub use ws::WsWriter;
#[cfg(feature = "openssl")]
pub(crate) const HAS_OPENSSL: bool = true;
#[cfg(not(feature = "openssl"))]

View File

@ -32,8 +32,7 @@
//! session data.
//!
//! ```rust
//! # extern crate actix;
//! # extern crate actix_web;
//! //#### # extern crate actix_web;
//! use actix_web::{server, App, HttpRequest, Result};
//! use actix_web::middleware::session::{RequestSession, SessionStorage, CookieSessionBackend};
//!
@ -59,7 +58,7 @@
//! )))
//! .bind("127.0.0.1:59880").unwrap()
//! .start();
//! # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
//! //#### # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
//! });
//! }
//! ```
@ -88,8 +87,8 @@ use middleware::{Middleware, Response, Started};
/// The helper trait to obtain your session data from a request.
///
/// ```rust
/// use actix_web::*;
/// use actix_web::middleware::session::RequestSession;
/// use actix_web::*;
///
/// fn index(mut req: HttpRequest) -> Result<&'static str> {
/// // access session data
@ -123,8 +122,8 @@ impl<S> RequestSession for HttpRequest<S> {
/// method. `RequestSession` trait is implemented for `HttpRequest`.
///
/// ```rust
/// use actix_web::*;
/// use actix_web::middleware::session::RequestSession;
/// use actix_web::*;
///
/// fn index(mut req: HttpRequest) -> Result<&'static str> {
/// // access session data
@ -230,15 +229,15 @@ unsafe impl Sync for SessionImplCell {}
///
/// ```rust
/// # extern crate actix_web;
/// use actix_web::middleware::session::{CookieSessionBackend, SessionStorage};
/// use actix_web::App;
/// use actix_web::middleware::session::{SessionStorage, CookieSessionBackend};
///
/// fn main() {
/// let app = App::new().middleware(
/// SessionStorage::new( // <- create session middleware
/// let app = App::new().middleware(SessionStorage::new(
/// // <- create session middleware
/// CookieSessionBackend::signed(&[0; 32]) // <- create cookie session backend
/// .secure(false))
/// );
/// .secure(false),
/// ));
/// }
/// ```
pub struct SessionStorage<T, S>(T, PhantomData<S>);

View File

@ -1,6 +1,4 @@
//! Http server
extern crate actix;
use std::net::Shutdown;
use std::{io, time};
@ -29,6 +27,7 @@ pub use self::srv::HttpServer;
#[doc(hidden)]
pub use self::helpers::write_content_length;
use actix::Message;
use body::Binary;
use error::Error;
use header::ContentEncoding;
@ -43,9 +42,8 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
/// This is shortcut for `server::HttpServer::new()` method.
///
/// ```rust
/// # extern crate actix_web;
/// use actix_web::actix::*;
/// use actix_web::{server, App, HttpResponse};
/// //#### # extern crate actix_web;
/// use actix_web::{actix, server, App, HttpResponse};
///
/// fn main() {
/// actix::System::run(|| {
@ -56,7 +54,7 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
/// .bind("127.0.0.1:59090").unwrap()
/// .start();
///
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
/// //#### # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
/// });
/// }
/// ```
@ -116,7 +114,7 @@ pub struct StopServer {
pub graceful: bool,
}
impl actix::Message for StopServer {
impl Message for StopServer {
type Result = Result<(), ()>;
}

View File

@ -1,12 +1,13 @@
extern crate actix;
use std::rc::Rc;
use std::sync::{mpsc as sync_mpsc, Arc};
use std::time::Duration;
use std::{io, net, thread};
use self::actix::actors::signal;
use self::actix::prelude::*;
use actix::{
fut, msgs, signal, Actor, ActorFuture, Addr, Arbiter, AsyncContext, Context,
ContextFutureSpawner, Handler, Response, StreamHandler, System, WrapFuture,
};
use futures::sync::mpsc;
use futures::{Future, Sink, Stream};
use mio;
@ -21,7 +22,7 @@ use native_tls::TlsAcceptor;
#[cfg(feature = "alpn")]
use openssl::ssl::{AlpnError, SslAcceptorBuilder};
use super::channel::{WrapperStream};
use super::channel::WrapperStream;
use super::settings::{ServerSettings, WorkerSettings};
use super::worker::{Conn, SocketInfo, StopWorker, StreamHandlerType, Worker};
use super::{IntoHttpHandler, IoStream, KeepAlive};
@ -408,19 +409,16 @@ impl<H: IntoHttpHandler> HttpServer<H> {
///
/// ```rust
/// extern crate actix_web;
/// extern crate actix;
/// use actix_web::{server, App, HttpResponse};
/// 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")
/// 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::Arbiter::system().do_send(actix::msgs::SystemExit(0));
/// //#### # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
/// });
/// }
/// ```
@ -485,10 +483,9 @@ impl<H: IntoHttpHandler> HttpServer<H> {
/// use actix_web::*;
///
/// fn main() {
/// HttpServer::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")
/// HttpServer::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")
/// .run();
/// }
/// ```
@ -723,7 +720,7 @@ impl<H: IntoHttpHandler> Handler<ResumeServer> for HttpServer<H> {
}
impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
type Result = actix::Response<(), ()>;
type Result = Response<(), ()>;
fn handle(&mut self, msg: StopServer, ctx: &mut Context<Self>) -> Self::Result {
// stop accept threads
@ -754,11 +751,11 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
// we need to stop system if server was spawned
if slf.exit {
ctx.run_later(Duration::from_millis(300), |_, _| {
Arbiter::system().do_send(actix::msgs::SystemExit(0))
Arbiter::system().do_send(msgs::SystemExit(0))
});
}
}
actix::fut::ok(())
fut::ok(())
})
.spawn(ctx);
}
@ -769,7 +766,7 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
// we need to stop system if server was spawned
if self.exit {
ctx.run_later(Duration::from_millis(300), |_, _| {
Arbiter::system().do_send(actix::msgs::SystemExit(0))
Arbiter::system().do_send(msgs::SystemExit(0))
});
}
Response::reply(Ok(()))

View File

@ -1,5 +1,3 @@
extern crate actix;
use futures::sync::oneshot;
use futures::Future;
use net2::TcpStreamExt;
@ -23,8 +21,8 @@ use openssl::ssl::SslAcceptor;
#[cfg(feature = "alpn")]
use tokio_openssl::SslAcceptorExt;
use self::actix::msgs::StopArbiter;
use self::actix::*;
use actix::msgs::StopArbiter;
use actix::{Actor, Arbiter, AsyncContext, Context, Handler, Message, Response};
use server::channel::HttpChannel;
use server::settings::WorkerSettings;

View File

@ -1,13 +1,11 @@
//! Various helpers for Actix applications to use during testing.
extern crate actix;
use std::rc::Rc;
use std::str::FromStr;
use std::sync::mpsc;
use std::{net, thread};
use self::actix::{msgs, Actor, Addr, Arbiter, System};
use actix_inner::{msgs, Actor, Addr, Arbiter, System};
use cookie::Cookie;
use futures::Future;
use http::header::HeaderName;
@ -409,11 +407,11 @@ impl<S: 'static> Iterator for TestApp<S> {
///
/// fn main() {
/// let resp = TestRequest::with_header("content-type", "text/plain")
/// .run(index).unwrap();
/// .run(index)
/// .unwrap();
/// assert_eq!(resp.status(), StatusCode::OK);
///
/// let resp = TestRequest::default()
/// .run(index).unwrap();
/// let resp = TestRequest::default().run(index).unwrap();
/// assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
/// }
/// ```

View File

@ -1,6 +1,4 @@
//! Http client request
extern crate actix;
use std::cell::UnsafeCell;
use std::rc::Rc;
use std::time::Duration;
@ -16,7 +14,7 @@ use http::{Error as HttpError, HttpTryFrom, StatusCode};
use rand;
use sha1::Sha1;
use self::actix::prelude::*;
use actix::{Addr, SystemService};
use body::Binary;
use error::{Error, UrlParseError};

View File

@ -25,7 +25,6 @@
//!
//! // Handler for ws::Message messages
//! impl StreamHandler<ws::Message, ws::ProtocolError> for Ws {
//!
//! fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
//! match msg {
//! ws::Message::Ping(msg) => ctx.pong(&msg),
@ -42,13 +41,11 @@
//! # .finish();
//! # }
//! ```
extern crate actix;
use bytes::Bytes;
use futures::{Async, Poll, Stream};
use http::{header, Method, StatusCode};
use self::actix::{Actor, AsyncContext, StreamHandler};
use super::actix::{Actor, AsyncContext, StreamHandler};
use body::Binary;
use error::{Error, PayloadError, ResponseError};