1
0
mirror of https://github.com/actix/examples synced 2025-06-28 09:50:36 +02:00

cleanup and cargo fmt

This commit is contained in:
Nikolay Kim
2018-05-20 21:03:29 -07:00
parent 2d97219195
commit e4f1833215
28 changed files with 108 additions and 112 deletions

View File

@ -121,8 +121,7 @@ impl Handler<ClientCommand> for ChatClient {
}
"/join" => {
if v.len() == 2 {
self.framed
.write(codec::ChatRequest::Join(v[1].to_owned()));
self.framed.write(codec::ChatRequest::Join(v[1].to_owned()));
} else {
println!("!!! room name is required");
}
@ -130,8 +129,7 @@ impl Handler<ClientCommand> for ChatClient {
_ => println!("!!! unknown command"),
}
} else {
self.framed
.write(codec::ChatRequest::Message(m.to_owned()));
self.framed.write(codec::ChatRequest::Message(m.to_owned()));
}
}
}

View File

@ -71,7 +71,7 @@ impl Encoder for ChatCodec {
let msg_ref: &[u8] = msg.as_ref();
dst.reserve(msg_ref.len() + 2);
dst.put_u16::<BigEndian>(msg_ref.len() as u16);
dst.put_u16_be(msg_ref.len() as u16);
dst.put(msg_ref);
Ok(())
@ -114,7 +114,7 @@ impl Encoder for ClientChatCodec {
let msg_ref: &[u8] = msg.as_ref();
dst.reserve(msg_ref.len() + 2);
dst.put_u16::<BigEndian>(msg_ref.len() as u16);
dst.put_u16_be(msg_ref.len() as u16);
dst.put(msg_ref);
Ok(())

View File

@ -19,7 +19,6 @@ use std::time::Instant;
use actix::*;
use actix_web::server::HttpServer;
use actix_web::ws::WsWriter;
use actix_web::{fs, http, ws, App, Error, HttpRequest, HttpResponse};
mod codec;
@ -88,9 +87,7 @@ impl Actor for WsChatSession {
fn stopping(&mut self, ctx: &mut Self::Context) -> Running {
// notify chat server
ctx.state()
.addr
.do_send(server::Disconnect { id: self.id });
ctx.state().addr.do_send(server::Disconnect { id: self.id });
Running::Stop
}
}

View File

@ -112,10 +112,7 @@ impl Handler<Connect> for ChatServer {
self.sessions.insert(id, msg.addr);
// auto join session to Main room
self.rooms
.get_mut(&"Main".to_owned())
.unwrap()
.insert(id);
self.rooms.get_mut(&"Main".to_owned()).unwrap().insert(id);
// send id back
id