mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
better document relationship with tokio
This commit is contained in:
parent
593fbde46a
commit
074d18209d
@ -152,6 +152,10 @@ method_macro!(Patch, patch);
|
|||||||
|
|
||||||
/// Marks async main function as the Actix Web system entry-point.
|
/// Marks async main function as the Actix Web system entry-point.
|
||||||
///
|
///
|
||||||
|
/// Note that Actix Web also works under `#[tokio::main]` since version 4.0. However, this macro is
|
||||||
|
/// still necessary for actor support (since actors use a `System`). Read more in the
|
||||||
|
/// [`actix_web::rt`](https://docs.rs/actix-web/4/actix_web/rt) module docs.
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// #[actix_web::main]
|
/// #[actix_web::main]
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
- Static assets
|
- Static assets
|
||||||
- SSL support using OpenSSL or Rustls
|
- SSL support using OpenSSL or Rustls
|
||||||
- Middlewares ([Logger, Session, CORS, etc](https://actix.rs/docs/middleware/))
|
- Middlewares ([Logger, Session, CORS, etc](https://actix.rs/docs/middleware/))
|
||||||
- Includes an async [HTTP client](https://docs.rs/awc/)
|
- Integrates with the [`awc` HTTP client](https://docs.rs/awc/)
|
||||||
- Runs on stable Rust 1.54+
|
- Runs on stable Rust 1.54+
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
@ -10,12 +10,16 @@ use crate::{
|
|||||||
/// The interface for request handlers.
|
/// The interface for request handlers.
|
||||||
///
|
///
|
||||||
/// # What Is A Request Handler
|
/// # What Is A Request Handler
|
||||||
/// A request handler has three requirements:
|
/// In short, a handler is just an async function that receives request-based arguments, in any
|
||||||
|
/// order, and returns something that can be converted to a response.
|
||||||
|
///
|
||||||
|
/// In particular, a request handler has three requirements:
|
||||||
/// 1. It is an async function (or a function/closure that returns an appropriate future);
|
/// 1. It is an async function (or a function/closure that returns an appropriate future);
|
||||||
/// 1. The function parameters (up to 12) implement [`FromRequest`];
|
/// 1. The function parameters (up to 12) implement [`FromRequest`];
|
||||||
/// 1. The async function (or future) resolves to a type that can be converted into an
|
/// 1. The async function (or future) resolves to a type that can be converted into an
|
||||||
/// [`HttpResponse`] (i.e., it implements the [`Responder`] trait).
|
/// [`HttpResponse`] (i.e., it implements the [`Responder`] trait).
|
||||||
///
|
///
|
||||||
|
///
|
||||||
/// # Compiler Errors
|
/// # Compiler Errors
|
||||||
/// If you get the error `the trait Handler<_> is not implemented`, then your handler does not
|
/// If you get the error `the trait Handler<_> is not implemented`, then your handler does not
|
||||||
/// fulfill the _first_ of the above requirements. Missing other requirements manifest as errors on
|
/// fulfill the _first_ of the above requirements. Missing other requirements manifest as errors on
|
||||||
|
@ -42,28 +42,29 @@
|
|||||||
//! and otherwise utilizing them.
|
//! and otherwise utilizing them.
|
||||||
//!
|
//!
|
||||||
//! # Features
|
//! # Features
|
||||||
//! * Supports *HTTP/1.x* and *HTTP/2*
|
//! - Supports HTTP/1.x and HTTP/2
|
||||||
//! * Streaming and pipelining
|
//! - Streaming and pipelining
|
||||||
//! * Keep-alive and slow requests handling
|
//! - Powerful [request routing](https://actix.rs/docs/url-dispatch/) with optional macros
|
||||||
//! * Client/server [WebSockets](https://actix.rs/docs/websockets/) support
|
//! - Full [Tokio](https://tokio.rs) compatibility
|
||||||
//! * Transparent content compression/decompression (br, gzip, deflate, zstd)
|
//! - Keep-alive and slow requests handling
|
||||||
//! * Powerful [request routing](https://actix.rs/docs/url-dispatch/)
|
//! - Client/server [WebSockets](https://actix.rs/docs/websockets/) support
|
||||||
//! * Multipart streams
|
//! - Transparent content compression/decompression (br, gzip, deflate, zstd)
|
||||||
//! * Static assets
|
//! - Multipart streams
|
||||||
//! * SSL support using OpenSSL or Rustls
|
//! - Static assets
|
||||||
//! * Middlewares ([Logger, Session, CORS, etc](https://actix.rs/docs/middleware/))
|
//! - SSL support using OpenSSL or Rustls
|
||||||
//! * Includes an async [HTTP client](https://docs.rs/awc/)
|
//! - Middlewares ([Logger, Session, CORS, etc](middleware))
|
||||||
//! * Runs on stable Rust 1.54+
|
//! - Integrates with the [`awc` HTTP client](https://docs.rs/awc/)
|
||||||
|
//! - Runs on stable Rust 1.54+
|
||||||
//!
|
//!
|
||||||
//! # Crate Features
|
//! # Crate Features
|
||||||
//! * `cookies` - cookies support (enabled by default)
|
//! - `cookies` - cookies support (enabled by default)
|
||||||
//! * `macros` - routing and runtime macros (enabled by default)
|
//! - `macros` - routing and runtime macros (enabled by default)
|
||||||
//! * `compress-brotli` - brotli content encoding compression support (enabled by default)
|
//! - `compress-brotli` - brotli content encoding compression support (enabled by default)
|
||||||
//! * `compress-gzip` - gzip and deflate content encoding compression support (enabled by default)
|
//! - `compress-gzip` - gzip and deflate content encoding compression support (enabled by default)
|
||||||
//! * `compress-zstd` - zstd content encoding compression support (enabled by default)
|
//! - `compress-zstd` - zstd content encoding compression support (enabled by default)
|
||||||
//! * `openssl` - HTTPS support via `openssl` crate, supports `HTTP/2`
|
//! - `openssl` - HTTPS support via `openssl` crate, supports `HTTP/2`
|
||||||
//! * `rustls` - HTTPS support via `rustls` crate, supports `HTTP/2`
|
//! - `rustls` - HTTPS support via `rustls` crate, supports `HTTP/2`
|
||||||
//! * `secure-cookies` - secure cookies support
|
//! - `secure-cookies` - secure cookies support
|
||||||
|
|
||||||
#![deny(rust_2018_idioms, nonstandard_style)]
|
#![deny(rust_2018_idioms, nonstandard_style)]
|
||||||
#![warn(future_incompatible)]
|
#![warn(future_incompatible)]
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
//! A selection of re-exports from [`actix-rt`] and [`tokio`].
|
//! A selection of re-exports from [`tokio`] and [`actix-rt`].
|
||||||
//!
|
//!
|
||||||
//! [`actix-rt`]: https://docs.rs/actix_rt
|
//! Actix Web runs on [Tokio], providing full[^compat] compatibility with its huge ecosystem of
|
||||||
//! [`tokio`]: https://docs.rs/tokio
|
//! crates. Each of the server's workers uses a single-threaded runtime. Read more about the
|
||||||
|
//! architecture in [`actix-rt`]'s docs.
|
||||||
//!
|
//!
|
||||||
//! # Running Actix Web Macro-less
|
//! # Running Actix Web Without Macros
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use actix_web::{middleware, rt, web, App, HttpRequest, HttpServer};
|
//! use actix_web::{middleware, rt, web, App, HttpRequest, HttpServer};
|
||||||
//!
|
//!
|
||||||
@ -12,19 +13,53 @@
|
|||||||
//! "Hello world!\r\n"
|
//! "Hello world!\r\n"
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! # fn main() -> std::io::Result<()> {
|
//! fn main() -> std::io::Result<()> {
|
||||||
//! rt::System::new().block_on(
|
//! rt::System::new().block_on(
|
||||||
|
//! HttpServer::new(|| {
|
||||||
|
//! App::new().service(web::resource("/").route(web::get().to(index)))
|
||||||
|
//! })
|
||||||
|
//! .bind(("127.0.0.1", 8080))?
|
||||||
|
//! .run()
|
||||||
|
//! )
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! # Running Actix Web Using `#[tokio::main]`
|
||||||
|
//! If you need to run something alongside Actix Web that uses Tokio's work stealing functionality,
|
||||||
|
//! you can run Actix Web under `#[tokio::main]`. The [`Server`](crate::dev::Server) object returned
|
||||||
|
//! from [`HttpServer::run`](crate::HttpServer::run) can also be [`spawn`]ed, if preferred.
|
||||||
|
//!
|
||||||
|
//! Note that `actix` actor support (and therefore WebSocket support through `actix-web-actors`)
|
||||||
|
//! still require `#[actix_web::main]` since they require a [`System`] to be set up.
|
||||||
|
//!
|
||||||
|
//! ```no_run
|
||||||
|
//! use actix_web::{get, middleware, rt, web, App, HttpRequest, HttpServer};
|
||||||
|
//!
|
||||||
|
//! #[get("/")]
|
||||||
|
//! async fn index(req: HttpRequest) -> &'static str {
|
||||||
|
//! println!("REQ: {:?}", req);
|
||||||
|
//! "Hello world!\r\n"
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! #[tokio::main]
|
||||||
|
//! async fn main() -> std::io::Result<()> {
|
||||||
//! HttpServer::new(|| {
|
//! HttpServer::new(|| {
|
||||||
//! App::new()
|
//! App::new().service(index)
|
||||||
//! .wrap(middleware::Logger::default())
|
|
||||||
//! .service(web::resource("/").route(web::get().to(index)))
|
|
||||||
//! })
|
//! })
|
||||||
//! .bind(("127.0.0.1", 8080))?
|
//! .bind(("127.0.0.1", 8080))?
|
||||||
//! .workers(1)
|
|
||||||
//! .run()
|
//! .run()
|
||||||
//! )
|
//! .await
|
||||||
//! # }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
//!
|
||||||
|
//! [^compat]: Crates that use Tokio's [`block_in_place`] will not work with Actix Web. Fortunately,
|
||||||
|
//! the vast majority of Tokio-based crates do not use it.
|
||||||
|
//!
|
||||||
|
//! [`actix-rt`]: https://docs.rs/actix_rt
|
||||||
|
//! [`tokio`]: https://docs.rs/tokio
|
||||||
|
//! [Tokio]: https://docs.rs/tokio
|
||||||
|
//! [`spawn`]: https://docs.rs/tokio/1/tokio/fn.spawn.html
|
||||||
|
//! [`block_in_place`]: https://docs.rs/tokio/1/tokio/task/fn.block_in_place.html
|
||||||
|
|
||||||
// In particular:
|
// In particular:
|
||||||
// - Omit the `Arbiter` types because they have limited value here.
|
// - Omit the `Arbiter` types because they have limited value here.
|
||||||
|
Loading…
Reference in New Issue
Block a user