actix_web_actors/
lib.rs

1//! Actix actors support for Actix Web.
2//!
3//! This crate is deprecated. Migrate to [`actix-ws`](https://crates.io/crates/actix-ws).
4//!
5//! # Examples
6//!
7//! ```no_run
8//! use actix::{Actor, StreamHandler};
9//! use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer};
10//! use actix_web_actors::ws;
11//!
12//! /// Define Websocket actor
13//! struct MyWs;
14//!
15//! impl Actor for MyWs {
16//!     type Context = ws::WebsocketContext<Self>;
17//! }
18//!
19//! /// Handler for ws::Message message
20//! impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
21//!     fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
22//!         match msg {
23//!             Ok(ws::Message::Ping(msg)) => ctx.pong(&msg),
24//!             Ok(ws::Message::Text(text)) => ctx.text(text),
25//!             Ok(ws::Message::Binary(bin)) => ctx.binary(bin),
26//!             _ => (),
27//!         }
28//!     }
29//! }
30//!
31//! #[get("/ws")]
32//! async fn index(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
33//!     ws::start(MyWs, &req, stream)
34//! }
35//!
36//! #[actix_web::main]
37//! async fn main() -> std::io::Result<()> {
38//!     HttpServer::new(|| App::new().service(index))
39//!         .bind(("127.0.0.1", 8080))?
40//!         .run()
41//!         .await
42//! }
43//! ```
44//!
45//! # Documentation & Community Resources
46//! In addition to this API documentation, several other resources are available:
47//!
48//! * [Website & User Guide](https://actix.rs/)
49//! * [Documentation for `actix_web`](actix_web)
50//! * [Examples Repository](https://github.com/actix/examples)
51//! * [Community Chat on Discord](https://discord.gg/NWpN5mmg3x)
52//!
53//! To get started navigating the API docs, you may consider looking at the following pages first:
54//!
55//! * [`ws`]: This module provides actor support for WebSockets.
56//!
57//! * [`HttpContext`]: This struct provides actor support for streaming HTTP responses.
58//!
59
60#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
61#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
62#![cfg_attr(docsrs, feature(doc_auto_cfg))]
63
64mod context;
65pub mod ws;
66
67pub use self::context::HttpContext;