mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 08:22:59 +01:00
re-arrange exports, some doc string updates
This commit is contained in:
parent
32052c2750
commit
ae6c9cb7fa
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web"
|
name = "actix-web"
|
||||||
version = "0.4.11"
|
version = "0.5.0-dev"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix web is a simple, pragmatic, extremely fast, web framework for Rust."
|
description = "Actix web is a simple, pragmatic, extremely fast, web framework for Rust."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -433,7 +433,7 @@ impl<S: 'static> StaticFiles<S> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets default resource which is used when no matched file could be found.
|
/// Sets default handler which is used when no matched file could be found.
|
||||||
pub fn default_handler<H: Handler<S>>(mut self, handler: H) -> StaticFiles<S> {
|
pub fn default_handler<H: Handler<S>>(mut self, handler: H) -> StaticFiles<S> {
|
||||||
self.default = Box::new(WrapHandler::new(handler));
|
self.default = Box::new(WrapHandler::new(handler));
|
||||||
self
|
self
|
||||||
|
@ -20,7 +20,7 @@ use router::Router;
|
|||||||
use payload::Payload;
|
use payload::Payload;
|
||||||
use httpmessage::HttpMessage;
|
use httpmessage::HttpMessage;
|
||||||
use httpresponse::{HttpResponse, HttpResponseBuilder};
|
use httpresponse::{HttpResponse, HttpResponseBuilder};
|
||||||
use helpers::SharedHttpInnerMessage;
|
use server::helpers::SharedHttpInnerMessage;
|
||||||
use error::{UrlGenerationError, CookieParseError, PayloadError};
|
use error::{UrlGenerationError, CookieParseError, PayloadError};
|
||||||
|
|
||||||
|
|
||||||
|
57
src/json.rs
57
src/json.rs
@ -1,4 +1,5 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::ops::{Deref, DerefMut};
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use futures::{Poll, Future, Stream};
|
use futures::{Poll, Future, Stream};
|
||||||
use http::header::CONTENT_LENGTH;
|
use http::header::CONTENT_LENGTH;
|
||||||
@ -15,11 +16,15 @@ use httprequest::HttpRequest;
|
|||||||
use httpresponse::HttpResponse;
|
use httpresponse::HttpResponse;
|
||||||
use extractor::HttpRequestExtractor;
|
use extractor::HttpRequestExtractor;
|
||||||
|
|
||||||
/// Json response helper
|
/// Json helper
|
||||||
///
|
///
|
||||||
/// The `Json` type allows you to respond with well-formed JSON data: simply return a value of
|
/// Json can be used for two different purpose. First is for json response generation
|
||||||
/// type Json<T> where T is the type of a structure to serialize into *JSON*. The
|
/// and second is for extracting typed information from request's payload.
|
||||||
/// type `T` must implement the `Serialize` trait from *serde*.
|
///
|
||||||
|
/// The `Json` type allows you to respond with well-formed JSON data: simply
|
||||||
|
/// return a value of type Json<T> where T is the type of a structure
|
||||||
|
/// to serialize into *JSON*. The type `T` must implement the `Serialize`
|
||||||
|
/// trait from *serde*.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate actix_web;
|
/// # extern crate actix_web;
|
||||||
@ -36,8 +41,52 @@ use extractor::HttpRequestExtractor;
|
|||||||
/// }
|
/// }
|
||||||
/// # fn main() {}
|
/// # fn main() {}
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// To extract typed information from request's body, the type `T` must implement the
|
||||||
|
/// `Deserialize` trait from *serde*.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # extern crate bytes;
|
||||||
|
/// # extern crate actix_web;
|
||||||
|
/// # extern crate futures;
|
||||||
|
/// #[macro_use] extern crate serde_derive;
|
||||||
|
/// # use actix_web::*;
|
||||||
|
/// use actix_web::Json;
|
||||||
|
///
|
||||||
|
/// #[derive(Deserialize)]
|
||||||
|
/// struct Info {
|
||||||
|
/// username: String,
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// /// extract `Info` using serde
|
||||||
|
/// fn index(info: Json<Info>) -> Result<String> {
|
||||||
|
/// Ok(format!("Welcome {}!", info.username))
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn main() {
|
||||||
|
/// let app = Application::new().resource(
|
||||||
|
/// "/index.html",
|
||||||
|
/// |r| r.method(Method::POST).with(index)); // <- use `with` extractor
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
pub struct Json<T>(pub T);
|
pub struct Json<T>(pub T);
|
||||||
|
|
||||||
|
impl<T> Deref for Json<T> {
|
||||||
|
type Target = T;
|
||||||
|
|
||||||
|
fn deref(&self) -> &T {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> DerefMut for Json<T> {
|
||||||
|
fn deref_mut(&mut self) -> &mut T {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> fmt::Debug for Json<T> where T: fmt::Debug {
|
impl<T> fmt::Debug for Json<T> where T: fmt::Debug {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "Json: {:?}", self.0)
|
write!(f, "Json: {:?}", self.0)
|
||||||
|
12
src/lib.rs
12
src/lib.rs
@ -107,7 +107,6 @@ mod application;
|
|||||||
mod body;
|
mod body;
|
||||||
mod context;
|
mod context;
|
||||||
mod handler;
|
mod handler;
|
||||||
mod helpers;
|
|
||||||
mod httpmessage;
|
mod httpmessage;
|
||||||
mod httprequest;
|
mod httprequest;
|
||||||
mod httpresponse;
|
mod httpresponse;
|
||||||
@ -141,8 +140,6 @@ pub use httpmessage::HttpMessage;
|
|||||||
pub use httprequest::HttpRequest;
|
pub use httprequest::HttpRequest;
|
||||||
pub use httpresponse::HttpResponse;
|
pub use httpresponse::HttpResponse;
|
||||||
pub use handler::{Either, Responder, NormalizePath, AsyncResponder, FutureResponse};
|
pub use handler::{Either, Responder, NormalizePath, AsyncResponder, FutureResponse};
|
||||||
pub use route::Route;
|
|
||||||
pub use resource::Resource;
|
|
||||||
pub use context::HttpContext;
|
pub use context::HttpContext;
|
||||||
pub use server::HttpServer;
|
pub use server::HttpServer;
|
||||||
pub use extractor::{Path, Query};
|
pub use extractor::{Path, Query};
|
||||||
@ -164,13 +161,18 @@ pub(crate) const HAS_TLS: bool = false;
|
|||||||
#[deprecated(since="0.4.4", note="please use `actix::header` module")]
|
#[deprecated(since="0.4.4", note="please use `actix::header` module")]
|
||||||
pub mod headers {
|
pub mod headers {
|
||||||
//! Headers implementation
|
//! Headers implementation
|
||||||
|
|
||||||
pub use httpresponse::ConnectionType;
|
pub use httpresponse::ConnectionType;
|
||||||
pub use cookie::{Cookie, CookieBuilder};
|
pub use cookie::{Cookie, CookieBuilder};
|
||||||
pub use http_range::HttpRange;
|
pub use http_range::HttpRange;
|
||||||
pub use header::ContentEncoding;
|
pub use header::ContentEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod helpers {
|
||||||
|
//! Various helpers
|
||||||
|
|
||||||
|
pub use handler::{NormalizePath};
|
||||||
|
}
|
||||||
|
|
||||||
pub mod dev {
|
pub mod dev {
|
||||||
//! The `actix-web` prelude for library developers
|
//! The `actix-web` prelude for library developers
|
||||||
//!
|
//!
|
||||||
@ -186,6 +188,8 @@ pub mod dev {
|
|||||||
pub use context::Drain;
|
pub use context::Drain;
|
||||||
pub use info::ConnectionInfo;
|
pub use info::ConnectionInfo;
|
||||||
pub use handler::{Handler, Reply};
|
pub use handler::{Handler, Reply};
|
||||||
|
pub use route::Route;
|
||||||
|
pub use resource::Resource;
|
||||||
pub use with::WithHandler;
|
pub use with::WithHandler;
|
||||||
pub use json::JsonBody;
|
pub use json::JsonBody;
|
||||||
pub use router::{Router, Pattern};
|
pub use router::{Router, Pattern};
|
||||||
|
@ -8,11 +8,11 @@ use tokio_io::AsyncWrite;
|
|||||||
use http::{Method, Version};
|
use http::{Method, Version};
|
||||||
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE};
|
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE};
|
||||||
|
|
||||||
use helpers;
|
|
||||||
use body::{Body, Binary};
|
use body::{Body, Binary};
|
||||||
use headers::ContentEncoding;
|
use headers::ContentEncoding;
|
||||||
use httprequest::HttpInnerMessage;
|
use httprequest::HttpInnerMessage;
|
||||||
use httpresponse::HttpResponse;
|
use httpresponse::HttpResponse;
|
||||||
|
use super::helpers;
|
||||||
use super::{Writer, WriterState, MAX_WRITE_BUFFER_SIZE};
|
use super::{Writer, WriterState, MAX_WRITE_BUFFER_SIZE};
|
||||||
use super::shared::SharedBytes;
|
use super::shared::SharedBytes;
|
||||||
use super::encoding::ContentEncoder;
|
use super::encoding::ContentEncoder;
|
||||||
|
@ -9,11 +9,11 @@ use http2::server::SendResponse;
|
|||||||
use http::{Version, HttpTryFrom, Response};
|
use http::{Version, HttpTryFrom, Response};
|
||||||
use http::header::{HeaderValue, CONNECTION, TRANSFER_ENCODING, DATE, CONTENT_LENGTH};
|
use http::header::{HeaderValue, CONNECTION, TRANSFER_ENCODING, DATE, CONTENT_LENGTH};
|
||||||
|
|
||||||
use helpers;
|
|
||||||
use body::{Body, Binary};
|
use body::{Body, Binary};
|
||||||
use headers::ContentEncoding;
|
use headers::ContentEncoding;
|
||||||
use httprequest::HttpInnerMessage;
|
use httprequest::HttpInnerMessage;
|
||||||
use httpresponse::HttpResponse;
|
use httpresponse::HttpResponse;
|
||||||
|
use super::helpers;
|
||||||
use super::encoding::ContentEncoder;
|
use super::encoding::ContentEncoder;
|
||||||
use super::shared::SharedBytes;
|
use super::shared::SharedBytes;
|
||||||
use super::settings::WorkerSettings;
|
use super::settings::WorkerSettings;
|
||||||
|
@ -16,6 +16,7 @@ mod h2;
|
|||||||
mod h1writer;
|
mod h1writer;
|
||||||
mod h2writer;
|
mod h2writer;
|
||||||
mod settings;
|
mod settings;
|
||||||
|
pub(crate) mod helpers;
|
||||||
pub(crate) mod shared;
|
pub(crate) mod shared;
|
||||||
pub(crate) mod utils;
|
pub(crate) mod utils;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use bytes::BytesMut;
|
|||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use futures_cpupool::{Builder, CpuPool};
|
use futures_cpupool::{Builder, CpuPool};
|
||||||
|
|
||||||
use helpers;
|
use super::helpers;
|
||||||
use super::KeepAlive;
|
use super::KeepAlive;
|
||||||
use super::channel::Node;
|
use super::channel::Node;
|
||||||
use super::shared::{SharedBytes, SharedBytesPool};
|
use super::shared::{SharedBytes, SharedBytesPool};
|
||||||
|
@ -268,6 +268,10 @@ struct Inner {
|
|||||||
closed: bool,
|
closed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Future that implementes client websocket handshake process.
|
||||||
|
///
|
||||||
|
/// It resolves to a pair of `ClientReadr` and `ClientWriter` that
|
||||||
|
/// can be used for reading and writing websocket frames.
|
||||||
pub struct ClientHandshake {
|
pub struct ClientHandshake {
|
||||||
request: Option<SendRequest>,
|
request: Option<SendRequest>,
|
||||||
tx: Option<UnboundedSender<Bytes>>,
|
tx: Option<UnboundedSender<Bytes>>,
|
||||||
|
@ -82,7 +82,7 @@ pub type WsError = ProtocolError;
|
|||||||
#[deprecated(since="0.4.2", note="please use `ws::HandshakeError` instead")]
|
#[deprecated(since="0.4.2", note="please use `ws::HandshakeError` instead")]
|
||||||
pub type WsHandshakeError = HandshakeError;
|
pub type WsHandshakeError = HandshakeError;
|
||||||
|
|
||||||
/// Websocket errors
|
/// Websocket protocol errors
|
||||||
#[derive(Fail, Debug)]
|
#[derive(Fail, Debug)]
|
||||||
pub enum ProtocolError {
|
pub enum ProtocolError {
|
||||||
/// Received an unmasked frame from client
|
/// Received an unmasked frame from client
|
||||||
|
Loading…
Reference in New Issue
Block a user