mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
better actix mod re-exports
This commit is contained in:
parent
80965d7a9a
commit
154cd3c5de
@ -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();
|
||||
|
@ -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,
|
||||
|
@ -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,14 +195,14 @@ 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 {
|
||||
/// name: String,
|
||||
/// }
|
||||
///
|
||||
/// fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
||||
/// fn index(mut req: HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {
|
||||
/// req.json() // <- get JsonBody future
|
||||
/// .from_err()
|
||||
/// .and_then(|val: MyObj| { // <- deserialized value
|
||||
@ -224,16 +226,15 @@ 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>> {
|
||||
/// fn index(mut req: HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {
|
||||
/// req.multipart().from_err() // <- get multipart stream for current request
|
||||
/// .and_then(|item| match item { // <- iterate over multipart items
|
||||
/// multipart::MultipartItem::Field(field) => {
|
||||
|
22
src/lib.rs
22
src/lib.rs
@ -6,17 +6,17 @@
|
||||
//! # use std::thread;
|
||||
//!
|
||||
//! fn index(info: Path<(String, u32)>) -> String {
|
||||
//! format!("Hello {}! id:{}", info.0, info.1)
|
||||
//! format!("Hello {}! id:{}", info.0, info.1)
|
||||
//! }
|
||||
//!
|
||||
//! 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"))]
|
||||
|
@ -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,13 +87,13 @@ 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
|
||||
/// if let Some(count) = req.session().get::<i32>("counter")? {
|
||||
/// req.session().set("counter", count+1)?;
|
||||
/// req.session().set("counter", count + 1)?;
|
||||
/// } else {
|
||||
/// req.session().set("counter", 1)?;
|
||||
/// }
|
||||
@ -123,13 +122,13 @@ 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
|
||||
/// if let Some(count) = req.session().get::<i32>("counter")? {
|
||||
/// req.session().set("counter", count+1)?;
|
||||
/// req.session().set("counter", count + 1)?;
|
||||
/// } else {
|
||||
/// req.session().set("counter", 1)?;
|
||||
/// }
|
||||
@ -200,7 +199,7 @@ impl Session {
|
||||
/// fn index(session: Session) -> Result<&'static str> {
|
||||
/// // access session data
|
||||
/// if let Some(count) = session.get::<i32>("counter")? {
|
||||
/// session.set("counter", count+1)?;
|
||||
/// session.set("counter", count + 1)?;
|
||||
/// } else {
|
||||
/// session.set("counter", 1)?;
|
||||
/// }
|
||||
@ -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
|
||||
/// CookieSessionBackend::signed(&[0; 32]) // <- create cookie session backend
|
||||
/// .secure(false))
|
||||
/// );
|
||||
/// let app = App::new().middleware(SessionStorage::new(
|
||||
/// // <- create session middleware
|
||||
/// CookieSessionBackend::signed(&[0; 32]) // <- create cookie session backend
|
||||
/// .secure(false),
|
||||
/// ));
|
||||
/// }
|
||||
/// ```
|
||||
pub struct SessionStorage<T, S>(T, PhantomData<S>);
|
||||
|
@ -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<(), ()>;
|
||||
}
|
||||
|
||||
|
@ -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,20 +409,17 @@ 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));
|
||||
/// });
|
||||
/// }
|
||||
/// ```
|
||||
pub fn start(mut self) -> Addr<Self> {
|
||||
@ -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(()))
|
||||
|
@ -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;
|
||||
|
12
src/test.rs
12
src/test.rs
@ -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);
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -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};
|
||||
|
@ -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};
|
||||
|
Loading…
Reference in New Issue
Block a user