mirror of https://github.com/fafhrd91/actix-web
fix(actix-web-actors): formatting
This commit is contained in:
parent
ef64f03c22
commit
eaff67150c
|
@ -14,31 +14,31 @@ use futures_core::Stream;
|
|||
use tokio::sync::oneshot::Sender;
|
||||
|
||||
/// Execution context for HTTP actors
|
||||
///
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
///
|
||||
/// A demonstration of [server-sent events](https://developer.mozilla.org/docs/Web/API/Server-sent_events) using actors:
|
||||
///
|
||||
///
|
||||
/// ```no_run
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
///
|
||||
/// use actix::{Actor, AsyncContext};
|
||||
/// use actix_web::{get, http::header, App, HttpResponse, HttpServer};
|
||||
/// use actix_web_actors::HttpContext;
|
||||
/// use bytes::Bytes;
|
||||
///
|
||||
///
|
||||
/// struct MyActor {
|
||||
/// count: usize,
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// impl Actor for MyActor {
|
||||
/// type Context = HttpContext<Self>;
|
||||
///
|
||||
///
|
||||
/// fn started(&mut self, ctx: &mut Self::Context) {
|
||||
/// ctx.run_later(Duration::from_millis(100), Self::write);
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// impl MyActor {
|
||||
/// fn write(&mut self, ctx: &mut HttpContext<Self>) {
|
||||
/// self.count += 1;
|
||||
|
@ -50,14 +50,14 @@ use tokio::sync::oneshot::Sender;
|
|||
/// }
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// #[get("/")]
|
||||
/// async fn index() -> HttpResponse {
|
||||
/// HttpResponse::Ok()
|
||||
/// .insert_header(header::ContentType(mime::TEXT_EVENT_STREAM))
|
||||
/// .streaming(HttpContext::create(MyActor { count: 0 }))
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// #[actix_web::main]
|
||||
/// async fn main() -> std::io::Result<()> {
|
||||
/// HttpServer::new(|| App::new().service(index))
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
//! Actix actors support for Actix Web.
|
||||
//!
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use actix::{Actor, StreamHandler};
|
||||
//! use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
||||
//! use actix_web_actors::ws;
|
||||
//!
|
||||
//!
|
||||
//! /// Define Websocket actor
|
||||
//! struct MyWs;
|
||||
//!
|
||||
//!
|
||||
//! impl Actor for MyWs {
|
||||
//! type Context = ws::WebsocketContext<Self>;
|
||||
//! }
|
||||
//!
|
||||
//!
|
||||
//! /// Handler for ws::Message message
|
||||
//! impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
|
||||
//! fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
|
||||
|
@ -25,12 +25,12 @@
|
|||
//! }
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//!
|
||||
//! #[get("/ws")]
|
||||
//! async fn index(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
|
||||
//! ws::start(MyWs, &req, stream)
|
||||
//! }
|
||||
//!
|
||||
//!
|
||||
//! #[actix_web::main]
|
||||
//! async fn main() -> std::io::Result<()> {
|
||||
//! HttpServer::new(|| App::new().service(index))
|
||||
|
@ -39,7 +39,7 @@
|
|||
//! .await
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! # Documentation & Community Resources
|
||||
//! In addition to this API documentation, several other resources are available:
|
||||
//!
|
||||
|
@ -53,7 +53,7 @@
|
|||
//! * [`ws`]: This module provides actor support for WebSockets.
|
||||
//!
|
||||
//! * [`HttpContext`]: This struct provides actor support for streaming HTTP responses.
|
||||
//!
|
||||
//!
|
||||
|
||||
#![deny(rust_2018_idioms, nonstandard_style)]
|
||||
#![warn(future_incompatible)]
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
//! Websocket integration.
|
||||
//!
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use actix::{Actor, StreamHandler};
|
||||
//! use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
||||
//! use actix_web_actors::ws;
|
||||
//!
|
||||
//!
|
||||
//! /// Define Websocket actor
|
||||
//! struct MyWs;
|
||||
//!
|
||||
//!
|
||||
//! impl Actor for MyWs {
|
||||
//! type Context = ws::WebsocketContext<Self>;
|
||||
//! }
|
||||
//!
|
||||
//!
|
||||
//! /// Handler for ws::Message message
|
||||
//! impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
|
||||
//! fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
|
||||
|
@ -25,14 +25,14 @@
|
|||
//! }
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//!
|
||||
//! #[get("/ws")]
|
||||
//! async fn websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
|
||||
//! ws::start(MyWs, &req, stream)
|
||||
//! }
|
||||
//!
|
||||
//!
|
||||
//! const MAX_FRAME_SIZE: usize = 16_384; // 16KiB
|
||||
//!
|
||||
//!
|
||||
//! #[get("/custom-ws")]
|
||||
//! async fn custom_websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
|
||||
//! // Create a Websocket session with a specific max frame size, and protocols.
|
||||
|
@ -41,7 +41,7 @@
|
|||
//! .protocols(&["A", "B"])
|
||||
//! .start()
|
||||
//! }
|
||||
//!
|
||||
//!
|
||||
//! #[actix_web::main]
|
||||
//! async fn main() -> std::io::Result<()> {
|
||||
//! HttpServer::new(|| {
|
||||
|
@ -54,7 +54,7 @@
|
|||
//! .await
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
|
@ -101,25 +101,25 @@ use tokio::sync::oneshot;
|
|||
/// # use actix::{Actor, StreamHandler};
|
||||
/// # use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
||||
/// # use actix_web_actors::ws;
|
||||
/// #
|
||||
/// #
|
||||
/// # struct MyWs;
|
||||
/// #
|
||||
/// #
|
||||
/// # impl Actor for MyWs {
|
||||
/// # type Context = ws::WebsocketContext<Self>;
|
||||
/// # }
|
||||
/// #
|
||||
/// #
|
||||
/// # /// Handler for ws::Message message
|
||||
/// # impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
|
||||
/// # fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {}
|
||||
/// # }
|
||||
/// #
|
||||
/// #
|
||||
/// #[get("/ws")]
|
||||
/// async fn websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
|
||||
/// ws::WsResponseBuilder::new(MyWs, &req, stream).start()
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// const MAX_FRAME_SIZE: usize = 16_384; // 16KiB
|
||||
///
|
||||
///
|
||||
/// #[get("/custom-ws")]
|
||||
/// async fn custom_websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
|
||||
/// // Create a Websocket session with a specific max frame size, codec, and protocols.
|
||||
|
@ -130,7 +130,7 @@ use tokio::sync::oneshot;
|
|||
/// .protocols(&["A", "B"])
|
||||
/// .start()
|
||||
/// }
|
||||
/// #
|
||||
/// #
|
||||
/// # #[actix_web::main]
|
||||
/// # async fn main() -> std::io::Result<()> {
|
||||
/// # HttpServer::new(|| {
|
||||
|
|
Loading…
Reference in New Issue