Change WebsocketContext to accept Bytes for ping

This needed to change the tests:
pong no longer takes a reference.
This makes the interface more similar to "test" and "binary".
This commit is contained in:
Patrick Himmelmann 2019-09-06 15:23:24 +02:00
parent e374f3c97c
commit e6f8686155
2 changed files with 5 additions and 5 deletions

View File

@ -345,14 +345,14 @@ where
/// Send ping frame
#[inline]
pub fn ping(&mut self, message: &str) {
self.write_raw(Message::Ping(message.to_string()));
pub fn ping<B: Into<Bytes>>(&mut self, message: B) {
self.write_raw(Message::Ping(message.into()));
}
/// Send pong frame
#[inline]
pub fn pong(&mut self, message: &str) {
self.write_raw(Message::Pong(message.to_string()));
pub fn pong<B: Into<Bytes>>(&mut self, message: B) {
self.write_raw(Message::Pong(message.into()));
}
/// Send close frame

View File

@ -15,7 +15,7 @@ impl Actor for Ws {
impl StreamHandler<ws::Message, ws::ProtocolError> for Ws {
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
match msg {
ws::Message::Ping(msg) => ctx.pong(&msg),
ws::Message::Ping(msg) => ctx.pong(msg),
ws::Message::Text(text) => ctx.text(text),
ws::Message::Binary(bin) => ctx.binary(bin),
ws::Message::Close(reason) => ctx.close(reason),