mirror of
https://github.com/actix/examples
synced 2025-06-26 17:17:42 +02:00
fmt
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
use actix_files::{Files, NamedFile};
|
||||
use actix_web::{
|
||||
middleware::Logger, web, App, Error, HttpRequest, HttpServer, Responder,
|
||||
};
|
||||
use actix_web::{middleware::Logger, web, App, Error, HttpRequest, HttpServer, Responder};
|
||||
use actix_web_actors::ws;
|
||||
|
||||
mod message;
|
||||
@ -14,10 +12,7 @@ async fn index() -> impl Responder {
|
||||
NamedFile::open_async("./static/index.html").await.unwrap()
|
||||
}
|
||||
|
||||
async fn chat_ws(
|
||||
req: HttpRequest,
|
||||
stream: web::Payload,
|
||||
) -> Result<impl Responder, Error> {
|
||||
async fn chat_ws(req: HttpRequest, stream: web::Payload) -> Result<impl Responder, Error> {
|
||||
ws::start(WsChatSession::default(), &req, stream)
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,7 @@ impl WsChatServer {
|
||||
Some(room)
|
||||
}
|
||||
|
||||
fn add_client_to_room(
|
||||
&mut self,
|
||||
room_name: &str,
|
||||
id: Option<usize>,
|
||||
client: Client,
|
||||
) -> usize {
|
||||
fn add_client_to_room(&mut self, room_name: &str, id: Option<usize>, client: Client) -> usize {
|
||||
let mut id = id.unwrap_or_else(rand::random::<usize>);
|
||||
|
||||
if let Some(room) = self.rooms.get_mut(room_name) {
|
||||
@ -50,12 +45,7 @@ impl WsChatServer {
|
||||
id
|
||||
}
|
||||
|
||||
fn send_chat_message(
|
||||
&mut self,
|
||||
room_name: &str,
|
||||
msg: &str,
|
||||
_src: usize,
|
||||
) -> Option<()> {
|
||||
fn send_chat_message(&mut self, room_name: &str, msg: &str, _src: usize) -> Option<()> {
|
||||
let mut room = self.take_room(room_name)?;
|
||||
|
||||
for (id, client) in room.drain() {
|
||||
|
@ -101,11 +101,7 @@ impl Handler<ChatMessage> for WsChatSession {
|
||||
}
|
||||
|
||||
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WsChatSession {
|
||||
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) {
|
||||
let msg = match msg {
|
||||
Err(_) => {
|
||||
ctx.stop();
|
||||
|
Reference in New Issue
Block a user