diff --git a/src/error.rs b/src/error.rs index ab24753..5c96dc7 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,9 +8,6 @@ use std::result; use std::str; use std::string; -use http; -use httparse; - use crate::protocol::Message; #[cfg(feature = "tls")] diff --git a/src/handshake/headers.rs b/src/handshake/headers.rs index 0c51008..8386f5a 100644 --- a/src/handshake/headers.rs +++ b/src/handshake/headers.rs @@ -1,8 +1,6 @@ //! HTTP Request and response header handling. -use http; use http::header::{HeaderMap, HeaderName, HeaderValue}; -use httparse; use httparse::Status; use super::machine::TryParse; diff --git a/src/handshake/mod.rs b/src/handshake/mod.rs index ce6b4dd..8350dc0 100644 --- a/src/handshake/mod.rs +++ b/src/handshake/mod.rs @@ -10,7 +10,6 @@ use std::error::Error as ErrorTrait; use std::fmt; use std::io::{Read, Write}; -use base64; use sha1::{Digest, Sha1}; use self::machine::{HandshakeMachine, RoundResult, StageResult, TryParse}; diff --git a/src/protocol/frame/frame.rs b/src/protocol/frame/frame.rs index e6a0009..38ce61c 100644 --- a/src/protocol/frame/frame.rs +++ b/src/protocol/frame/frame.rs @@ -310,10 +310,7 @@ impl Frame { #[inline] pub fn message(data: Vec, opcode: OpCode, is_final: bool) -> Frame { debug_assert!( - match opcode { - OpCode::Data(_) => true, - _ => false, - }, + matches!(opcode, OpCode::Data(_)), "Invalid opcode for data frame." ); diff --git a/src/protocol/message.rs b/src/protocol/message.rs index 7019494..d1778f1 100644 --- a/src/protocol/message.rs +++ b/src/protocol/message.rs @@ -7,8 +7,6 @@ use super::frame::CloseFrame; use crate::error::{Error, Result}; mod string_collect { - - use utf8; use utf8::DecodeError; use crate::error::{Error, Result}; @@ -202,42 +200,27 @@ impl Message { /// Indicates whether a message is a text message. pub fn is_text(&self) -> bool { - match *self { - Message::Text(_) => true, - _ => false, - } + matches!(*self, Message::Text(_)) } /// Indicates whether a message is a binary message. pub fn is_binary(&self) -> bool { - match *self { - Message::Binary(_) => true, - _ => false, - } + matches!(*self, Message::Binary(_)) } /// Indicates whether a message is a ping message. pub fn is_ping(&self) -> bool { - match *self { - Message::Ping(_) => true, - _ => false, - } + matches!(*self, Message::Ping(_)) } /// Indicates whether a message is a pong message. pub fn is_pong(&self) -> bool { - match *self { - Message::Pong(_) => true, - _ => false, - } + matches!(*self, Message::Pong(_)) } /// Indicates whether a message ia s close message. pub fn is_close(&self) -> bool { - match *self { - Message::Close(_) => true, - _ => false, - } + matches!(*self, Message::Close(_)) } /// Get the length of the WebSocket message. diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 97b376e..8137393 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -626,20 +626,14 @@ enum WebSocketState { impl WebSocketState { /// Tell if we're allowed to process normal messages. fn is_active(self) -> bool { - match self { - WebSocketState::Active => true, - _ => false, - } + matches!(self, WebSocketState::Active) } /// Tell if we should process incoming data. Note that if we send a close frame /// but the remote hasn't confirmed, they might have sent data before they receive our /// close frame, so we should still pass those to client code, hence ClosedByUs is valid. fn can_read(self) -> bool { - match self { - WebSocketState::Active | WebSocketState::ClosedByUs => true, - _ => false, - } + matches!(self, WebSocketState::Active | WebSocketState::ClosedByUs) } /// Check if the state is active, return error if not.