Merge pull request #154 from Horki/matches_macro_fix

matches!: use macros; remove unused imports
pull/156/head
Daniel Abramov 4 years ago committed by GitHub
commit 2e711fb6fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/error.rs
  2. 2
      src/handshake/headers.rs
  3. 1
      src/handshake/mod.rs
  4. 5
      src/protocol/frame/frame.rs
  5. 27
      src/protocol/message.rs
  6. 10
      src/protocol/mod.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")]

@ -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;

@ -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};

@ -310,10 +310,7 @@ impl Frame {
#[inline]
pub fn message(data: Vec<u8>, opcode: OpCode, is_final: bool) -> Frame {
debug_assert!(
match opcode {
OpCode::Data(_) => true,
_ => false,
},
matches!(opcode, OpCode::Data(_)),
"Invalid opcode for data frame."
);

@ -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.

@ -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.

Loading…
Cancel
Save