From 80965d7a9ad62fddb02f8b9dc87110448e5ef8a5 Mon Sep 17 00:00:00 2001 From: Douman Date: Thu, 31 May 2018 20:43:14 +0300 Subject: [PATCH] Re-export actix dependency. Closes #260 (#264) - Re-export actix's prelude into actix namespace - Removing implicit dependency on root's actix module --- src/client/connector.rs | 10 ++++++---- src/client/mod.rs | 2 -- src/client/pipeline.rs | 4 +++- src/client/request.rs | 1 - src/context.rs | 8 +++++--- src/httpmessage.rs | 2 +- src/lib.rs | 8 +++++++- src/middleware/identity.rs | 1 - src/middleware/session.rs | 1 - src/server/mod.rs | 6 +++--- src/server/srv.rs | 11 ++++++----- src/server/worker.rs | 6 ++++-- src/test.rs | 5 +++-- src/ws/client.rs | 4 +++- src/ws/context.rs | 8 +++++--- src/ws/mod.rs | 7 ++++--- 16 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/client/connector.rs b/src/client/connector.rs index 65d4ded0..82d932e4 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -1,12 +1,14 @@ +extern crate actix; + use std::collections::{HashMap, VecDeque}; use std::net::Shutdown; use std::time::{Duration, Instant}; use std::{fmt, io, mem, time}; -use actix::actors::{Connect as ResolveConnect, Connector, ConnectorError}; -use actix::fut::WrapFuture; -use actix::registry::SystemService; -use actix::{ +use self::actix::actors::{Connect as ResolveConnect, Connector, ConnectorError}; +use self::actix::fut::WrapFuture; +use self::actix::registry::SystemService; +use self::actix::{ fut, Actor, ActorFuture, ActorResponse, AsyncContext, Context, ContextFutureSpawner, Handler, Message, Recipient, StreamHandler, Supervised, }; diff --git a/src/client/mod.rs b/src/client/mod.rs index 8aded011..0e7befc3 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1,7 +1,6 @@ //! Http client api //! //! ```rust -//! # extern crate actix; //! # extern crate actix_web; //! # extern crate futures; //! # extern crate tokio; @@ -63,7 +62,6 @@ impl ResponseError for SendRequestError { /// /// /// ```rust -/// # extern crate actix; /// # extern crate actix_web; /// # extern crate futures; /// # extern crate tokio; diff --git a/src/client/pipeline.rs b/src/client/pipeline.rs index a2105ecb..84593677 100644 --- a/src/client/pipeline.rs +++ b/src/client/pipeline.rs @@ -1,3 +1,5 @@ +extern crate actix; + use bytes::{Bytes, BytesMut}; use futures::sync::oneshot; use futures::{Async, Future, Poll}; @@ -6,7 +8,7 @@ use std::time::{Duration, Instant}; use std::{io, mem}; use tokio_timer::Delay; -use actix::prelude::*; +use self::actix::prelude::*; use super::{ ClientBody, ClientBodyStream, ClientConnector, ClientConnectorError, ClientRequest, diff --git a/src/client/request.rs b/src/client/request.rs index 97b97e01..eebf8e00 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -25,7 +25,6 @@ use httprequest::HttpRequest; /// An HTTP Client Request /// /// ```rust -/// # extern crate actix; /// # extern crate actix_web; /// # extern crate futures; /// # extern crate tokio; diff --git a/src/context.rs b/src/context.rs index b40b4bbb..3f8cf5ee 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,12 +1,14 @@ +extern crate actix; + use futures::sync::oneshot; use futures::sync::oneshot::Sender; use futures::{Async, Future, Poll}; use smallvec::SmallVec; use std::marker::PhantomData; -use actix::dev::{ContextImpl, Envelope, ToEnvelope}; -use actix::fut::ActorFuture; -use actix::{ +use self::actix::dev::{ContextImpl, Envelope, ToEnvelope}; +use self::actix::fut::ActorFuture; +use self::actix::{ Actor, ActorContext, ActorState, Addr, AsyncContext, Handler, Message, SpawnHandle, }; diff --git a/src/httpmessage.rs b/src/httpmessage.rs index 2f23e653..2f0a9c99 100644 --- a/src/httpmessage.rs +++ b/src/httpmessage.rs @@ -229,8 +229,8 @@ pub trait HttpMessage { /// # extern crate env_logger; /// # extern crate futures; /// # use std::str; - /// # use actix::*; /// # use actix_web::*; + /// # use actix::*; /// # use futures::{Future, Stream}; /// # use futures::future::{ok, result, Either}; /// fn index(mut req: HttpRequest) -> Box> { diff --git a/src/lib.rs b/src/lib.rs index a428b08b..8d728f99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -132,7 +132,7 @@ extern crate serde_json; extern crate serde_urlencoded; extern crate smallvec; #[macro_use] -extern crate actix; +pub extern crate actix as actix_inner; #[cfg(test)] #[macro_use] @@ -195,6 +195,12 @@ pub use httpresponse::HttpResponse; pub use json::Json; pub use scope::Scope; +pub mod actix { + //! Re-exports [actix's](https://docs.rs/actix) prelude + + pub use actix_inner::prelude::*; +} + #[doc(hidden)] #[deprecated(since = "0.6.2", note = "please use `use actix_web::ws::WsWriter`")] pub use ws::WsWriter; diff --git a/src/middleware/identity.rs b/src/middleware/identity.rs index 36317ebc..54d97a1c 100644 --- a/src/middleware/identity.rs +++ b/src/middleware/identity.rs @@ -143,7 +143,6 @@ pub trait IdentityPolicy: Sized + 'static { /// Request identity middleware /// /// ```rust -/// # extern crate actix; /// # extern crate actix_web; /// use actix_web::App; /// use actix_web::middleware::identity::{IdentityService, CookieIdentityPolicy}; diff --git a/src/middleware/session.rs b/src/middleware/session.rs index 57f42a11..f80d1f11 100644 --- a/src/middleware/session.rs +++ b/src/middleware/session.rs @@ -229,7 +229,6 @@ unsafe impl Sync for SessionImplCell {} /// Session storage middleware /// /// ```rust -/// # extern crate actix; /// # extern crate actix_web; /// use actix_web::App; /// use actix_web::middleware::session::{SessionStorage, CookieSessionBackend}; diff --git a/src/server/mod.rs b/src/server/mod.rs index 26876483..32138f30 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,8 +1,9 @@ //! Http server +extern crate actix; + use std::net::Shutdown; use std::{io, time}; -use actix; use bytes::BytesMut; use futures::{Async, Poll}; use tokio_io::{AsyncRead, AsyncWrite}; @@ -42,9 +43,8 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536; /// This is shortcut for `server::HttpServer::new()` method. /// /// ```rust -/// # extern crate actix; /// # extern crate actix_web; -/// use actix::*; +/// use actix_web::actix::*; /// use actix_web::{server, App, HttpResponse}; /// /// fn main() { diff --git a/src/server/srv.rs b/src/server/srv.rs index df6a4b9d..5ea28d6c 100644 --- a/src/server/srv.rs +++ b/src/server/srv.rs @@ -1,10 +1,12 @@ +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 actix::actors::signal; -use actix::prelude::*; +use self::actix::actors::signal; +use self::actix::prelude::*; use futures::sync::mpsc; use futures::{Future, Sink, Stream}; use mio; @@ -19,7 +21,7 @@ use native_tls::TlsAcceptor; #[cfg(feature = "alpn")] use openssl::ssl::{AlpnError, SslAcceptorBuilder}; -use super::channel::{HttpChannel, WrapperStream}; +use super::channel::{WrapperStream}; use super::settings::{ServerSettings, WorkerSettings}; use super::worker::{Conn, SocketInfo, StopWorker, StreamHandlerType, Worker}; use super::{IntoHttpHandler, IoStream, KeepAlive}; @@ -405,8 +407,8 @@ impl HttpServer { /// This method requires to run within properly configured `Actix` system. /// /// ```rust - /// extern crate actix; /// extern crate actix_web; + /// extern crate actix; /// use actix_web::{server, App, HttpResponse}; /// /// fn main() { @@ -478,7 +480,6 @@ impl HttpServer { /// /// ```rust,ignore /// # extern crate futures; - /// # extern crate actix; /// # extern crate actix_web; /// # use futures::Future; /// use actix_web::*; diff --git a/src/server/worker.rs b/src/server/worker.rs index d9cca29f..636f859a 100644 --- a/src/server/worker.rs +++ b/src/server/worker.rs @@ -1,3 +1,5 @@ +extern crate actix; + use futures::sync::oneshot; use futures::Future; use net2::TcpStreamExt; @@ -21,8 +23,8 @@ use openssl::ssl::SslAcceptor; #[cfg(feature = "alpn")] use tokio_openssl::SslAcceptorExt; -use actix::msgs::StopArbiter; -use actix::*; +use self::actix::msgs::StopArbiter; +use self::actix::*; use server::channel::HttpChannel; use server::settings::WorkerSettings; diff --git a/src/test.rs b/src/test.rs index 558695ad..b022e35e 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,11 +1,13 @@ //! 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 actix::{msgs, Actor, Addr, Arbiter, System}; +use self::actix::{msgs, Actor, Addr, Arbiter, System}; use cookie::Cookie; use futures::Future; use http::header::HeaderName; @@ -40,7 +42,6 @@ use ws; /// # Examples /// /// ```rust -/// # extern crate actix; /// # extern crate actix_web; /// # use actix_web::*; /// # diff --git a/src/ws/client.rs b/src/ws/client.rs index fcf6ed40..ac77a28f 100644 --- a/src/ws/client.rs +++ b/src/ws/client.rs @@ -1,4 +1,6 @@ //! Http client request +extern crate actix; + use std::cell::UnsafeCell; use std::rc::Rc; use std::time::Duration; @@ -14,7 +16,7 @@ use http::{Error as HttpError, HttpTryFrom, StatusCode}; use rand; use sha1::Sha1; -use actix::prelude::*; +use self::actix::prelude::*; use body::Binary; use error::{Error, UrlParseError}; diff --git a/src/ws/context.rs b/src/ws/context.rs index 2d7802b0..48f37f22 100644 --- a/src/ws/context.rs +++ b/src/ws/context.rs @@ -1,10 +1,12 @@ +extern crate actix; + use futures::sync::oneshot::{self, Sender}; use futures::{Async, Poll}; use smallvec::SmallVec; -use actix::dev::{ContextImpl, Envelope, ToEnvelope}; -use actix::fut::ActorFuture; -use actix::{ +use self::actix::dev::{ContextImpl, Envelope, ToEnvelope}; +use self::actix::fut::ActorFuture; +use self::actix::{ Actor, ActorContext, ActorState, Addr, AsyncContext, Handler, Message, SpawnHandle, }; diff --git a/src/ws/mod.rs b/src/ws/mod.rs index 7f72dea1..61ec7df9 100644 --- a/src/ws/mod.rs +++ b/src/ws/mod.rs @@ -7,9 +7,8 @@ //! ## Example //! //! ```rust -//! # extern crate actix; //! # extern crate actix_web; -//! # use actix::*; +//! # use actix_web::actix::*; //! # use actix_web::*; //! use actix_web::{ws, HttpRequest, HttpResponse}; //! @@ -43,11 +42,13 @@ //! # .finish(); //! # } //! ``` +extern crate actix; + use bytes::Bytes; use futures::{Async, Poll, Stream}; use http::{header, Method, StatusCode}; -use actix::{Actor, AsyncContext, StreamHandler}; +use self::actix::{Actor, AsyncContext, StreamHandler}; use body::Binary; use error::{Error, PayloadError, ResponseError};