fix(actix-web-actors): formatting

This commit is contained in:
Nerixyz 2022-06-19 20:52:48 +02:00
parent ef64f03c22
commit eaff67150c
No known key found for this signature in database
GPG Key ID: 946BA188C5609CCC
3 changed files with 36 additions and 36 deletions

View File

@ -14,31 +14,31 @@ use futures_core::Stream;
use tokio::sync::oneshot::Sender; use tokio::sync::oneshot::Sender;
/// Execution context for HTTP actors /// Execution context for HTTP actors
/// ///
/// # Example /// # Example
/// ///
/// A demonstration of [server-sent events](https://developer.mozilla.org/docs/Web/API/Server-sent_events) using actors: /// A demonstration of [server-sent events](https://developer.mozilla.org/docs/Web/API/Server-sent_events) using actors:
/// ///
/// ```no_run /// ```no_run
/// use std::time::Duration; /// use std::time::Duration;
/// ///
/// use actix::{Actor, AsyncContext}; /// use actix::{Actor, AsyncContext};
/// use actix_web::{get, http::header, App, HttpResponse, HttpServer}; /// use actix_web::{get, http::header, App, HttpResponse, HttpServer};
/// use actix_web_actors::HttpContext; /// use actix_web_actors::HttpContext;
/// use bytes::Bytes; /// use bytes::Bytes;
/// ///
/// struct MyActor { /// struct MyActor {
/// count: usize, /// count: usize,
/// } /// }
/// ///
/// impl Actor for MyActor { /// impl Actor for MyActor {
/// type Context = HttpContext<Self>; /// type Context = HttpContext<Self>;
/// ///
/// fn started(&mut self, ctx: &mut Self::Context) { /// fn started(&mut self, ctx: &mut Self::Context) {
/// ctx.run_later(Duration::from_millis(100), Self::write); /// ctx.run_later(Duration::from_millis(100), Self::write);
/// } /// }
/// } /// }
/// ///
/// impl MyActor { /// impl MyActor {
/// fn write(&mut self, ctx: &mut HttpContext<Self>) { /// fn write(&mut self, ctx: &mut HttpContext<Self>) {
/// self.count += 1; /// self.count += 1;
@ -50,14 +50,14 @@ use tokio::sync::oneshot::Sender;
/// } /// }
/// } /// }
/// } /// }
/// ///
/// #[get("/")] /// #[get("/")]
/// async fn index() -> HttpResponse { /// async fn index() -> HttpResponse {
/// HttpResponse::Ok() /// HttpResponse::Ok()
/// .insert_header(header::ContentType(mime::TEXT_EVENT_STREAM)) /// .insert_header(header::ContentType(mime::TEXT_EVENT_STREAM))
/// .streaming(HttpContext::create(MyActor { count: 0 })) /// .streaming(HttpContext::create(MyActor { count: 0 }))
/// } /// }
/// ///
/// #[actix_web::main] /// #[actix_web::main]
/// async fn main() -> std::io::Result<()> { /// async fn main() -> std::io::Result<()> {
/// HttpServer::new(|| App::new().service(index)) /// HttpServer::new(|| App::new().service(index))

View File

@ -1,19 +1,19 @@
//! Actix actors support for Actix Web. //! Actix actors support for Actix Web.
//! //!
//! # Examples //! # Examples
//! //!
//! ```no_run //! ```no_run
//! use actix::{Actor, StreamHandler}; //! use actix::{Actor, StreamHandler};
//! use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer}; //! use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer};
//! use actix_web_actors::ws; //! use actix_web_actors::ws;
//! //!
//! /// Define Websocket actor //! /// Define Websocket actor
//! struct MyWs; //! struct MyWs;
//! //!
//! impl Actor for MyWs { //! impl Actor for MyWs {
//! type Context = ws::WebsocketContext<Self>; //! type Context = ws::WebsocketContext<Self>;
//! } //! }
//! //!
//! /// Handler for ws::Message message //! /// Handler for ws::Message message
//! impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs { //! impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
//! fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) { //! fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
@ -25,12 +25,12 @@
//! } //! }
//! } //! }
//! } //! }
//! //!
//! #[get("/ws")] //! #[get("/ws")]
//! async fn index(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> { //! async fn index(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
//! ws::start(MyWs, &req, stream) //! ws::start(MyWs, &req, stream)
//! } //! }
//! //!
//! #[actix_web::main] //! #[actix_web::main]
//! async fn main() -> std::io::Result<()> { //! async fn main() -> std::io::Result<()> {
//! HttpServer::new(|| App::new().service(index)) //! HttpServer::new(|| App::new().service(index))
@ -39,7 +39,7 @@
//! .await //! .await
//! } //! }
//! ``` //! ```
//! //!
//! # Documentation & Community Resources //! # Documentation & Community Resources
//! In addition to this API documentation, several other resources are available: //! In addition to this API documentation, several other resources are available:
//! //!
@ -53,7 +53,7 @@
//! * [`ws`]: This module provides actor support for WebSockets. //! * [`ws`]: This module provides actor support for WebSockets.
//! //!
//! * [`HttpContext`]: This struct provides actor support for streaming HTTP responses. //! * [`HttpContext`]: This struct provides actor support for streaming HTTP responses.
//! //!
#![deny(rust_2018_idioms, nonstandard_style)] #![deny(rust_2018_idioms, nonstandard_style)]
#![warn(future_incompatible)] #![warn(future_incompatible)]

View File

@ -1,19 +1,19 @@
//! Websocket integration. //! Websocket integration.
//! //!
//! # Examples //! # Examples
//! //!
//! ```no_run //! ```no_run
//! use actix::{Actor, StreamHandler}; //! use actix::{Actor, StreamHandler};
//! use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer}; //! use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer};
//! use actix_web_actors::ws; //! use actix_web_actors::ws;
//! //!
//! /// Define Websocket actor //! /// Define Websocket actor
//! struct MyWs; //! struct MyWs;
//! //!
//! impl Actor for MyWs { //! impl Actor for MyWs {
//! type Context = ws::WebsocketContext<Self>; //! type Context = ws::WebsocketContext<Self>;
//! } //! }
//! //!
//! /// Handler for ws::Message message //! /// Handler for ws::Message message
//! impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs { //! impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
//! fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) { //! fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
@ -25,14 +25,14 @@
//! } //! }
//! } //! }
//! } //! }
//! //!
//! #[get("/ws")] //! #[get("/ws")]
//! async fn websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> { //! async fn websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
//! ws::start(MyWs, &req, stream) //! ws::start(MyWs, &req, stream)
//! } //! }
//! //!
//! const MAX_FRAME_SIZE: usize = 16_384; // 16KiB //! const MAX_FRAME_SIZE: usize = 16_384; // 16KiB
//! //!
//! #[get("/custom-ws")] //! #[get("/custom-ws")]
//! async fn custom_websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> { //! async fn custom_websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
//! // Create a Websocket session with a specific max frame size, and protocols. //! // Create a Websocket session with a specific max frame size, and protocols.
@ -41,7 +41,7 @@
//! .protocols(&["A", "B"]) //! .protocols(&["A", "B"])
//! .start() //! .start()
//! } //! }
//! //!
//! #[actix_web::main] //! #[actix_web::main]
//! async fn main() -> std::io::Result<()> { //! async fn main() -> std::io::Result<()> {
//! HttpServer::new(|| { //! HttpServer::new(|| {
@ -54,7 +54,7 @@
//! .await //! .await
//! } //! }
//! ``` //! ```
//! //!
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
@ -101,25 +101,25 @@ use tokio::sync::oneshot;
/// # use actix::{Actor, StreamHandler}; /// # use actix::{Actor, StreamHandler};
/// # use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer}; /// # use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer};
/// # use actix_web_actors::ws; /// # use actix_web_actors::ws;
/// # /// #
/// # struct MyWs; /// # struct MyWs;
/// # /// #
/// # impl Actor for MyWs { /// # impl Actor for MyWs {
/// # type Context = ws::WebsocketContext<Self>; /// # type Context = ws::WebsocketContext<Self>;
/// # } /// # }
/// # /// #
/// # /// Handler for ws::Message message /// # /// Handler for ws::Message message
/// # impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs { /// # impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
/// # fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {} /// # fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {}
/// # } /// # }
/// # /// #
/// #[get("/ws")] /// #[get("/ws")]
/// async fn websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> { /// async fn websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
/// ws::WsResponseBuilder::new(MyWs, &req, stream).start() /// ws::WsResponseBuilder::new(MyWs, &req, stream).start()
/// } /// }
/// ///
/// const MAX_FRAME_SIZE: usize = 16_384; // 16KiB /// const MAX_FRAME_SIZE: usize = 16_384; // 16KiB
/// ///
/// #[get("/custom-ws")] /// #[get("/custom-ws")]
/// async fn custom_websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> { /// 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. /// // Create a Websocket session with a specific max frame size, codec, and protocols.
@ -130,7 +130,7 @@ use tokio::sync::oneshot;
/// .protocols(&["A", "B"]) /// .protocols(&["A", "B"])
/// .start() /// .start()
/// } /// }
/// # /// #
/// # #[actix_web::main] /// # #[actix_web::main]
/// # async fn main() -> std::io::Result<()> { /// # async fn main() -> std::io::Result<()> {
/// # HttpServer::new(|| { /// # HttpServer::new(|| {