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::str;
use std::string; use std::string;
use http;
use httparse;
use crate::protocol::Message; use crate::protocol::Message;
#[cfg(feature = "tls")] #[cfg(feature = "tls")]

@ -1,8 +1,6 @@
//! HTTP Request and response header handling. //! HTTP Request and response header handling.
use http;
use http::header::{HeaderMap, HeaderName, HeaderValue}; use http::header::{HeaderMap, HeaderName, HeaderValue};
use httparse;
use httparse::Status; use httparse::Status;
use super::machine::TryParse; use super::machine::TryParse;

@ -10,7 +10,6 @@ use std::error::Error as ErrorTrait;
use std::fmt; use std::fmt;
use std::io::{Read, Write}; use std::io::{Read, Write};
use base64;
use sha1::{Digest, Sha1}; use sha1::{Digest, Sha1};
use self::machine::{HandshakeMachine, RoundResult, StageResult, TryParse}; use self::machine::{HandshakeMachine, RoundResult, StageResult, TryParse};

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

@ -7,8 +7,6 @@ use super::frame::CloseFrame;
use crate::error::{Error, Result}; use crate::error::{Error, Result};
mod string_collect { mod string_collect {
use utf8;
use utf8::DecodeError; use utf8::DecodeError;
use crate::error::{Error, Result}; use crate::error::{Error, Result};
@ -202,42 +200,27 @@ impl Message {
/// Indicates whether a message is a text message. /// Indicates whether a message is a text message.
pub fn is_text(&self) -> bool { pub fn is_text(&self) -> bool {
match *self { matches!(*self, Message::Text(_))
Message::Text(_) => true,
_ => false,
}
} }
/// Indicates whether a message is a binary message. /// Indicates whether a message is a binary message.
pub fn is_binary(&self) -> bool { pub fn is_binary(&self) -> bool {
match *self { matches!(*self, Message::Binary(_))
Message::Binary(_) => true,
_ => false,
}
} }
/// Indicates whether a message is a ping message. /// Indicates whether a message is a ping message.
pub fn is_ping(&self) -> bool { pub fn is_ping(&self) -> bool {
match *self { matches!(*self, Message::Ping(_))
Message::Ping(_) => true,
_ => false,
}
} }
/// Indicates whether a message is a pong message. /// Indicates whether a message is a pong message.
pub fn is_pong(&self) -> bool { pub fn is_pong(&self) -> bool {
match *self { matches!(*self, Message::Pong(_))
Message::Pong(_) => true,
_ => false,
}
} }
/// Indicates whether a message ia s close message. /// Indicates whether a message ia s close message.
pub fn is_close(&self) -> bool { pub fn is_close(&self) -> bool {
match *self { matches!(*self, Message::Close(_))
Message::Close(_) => true,
_ => false,
}
} }
/// Get the length of the WebSocket message. /// Get the length of the WebSocket message.

@ -626,20 +626,14 @@ enum WebSocketState {
impl WebSocketState { impl WebSocketState {
/// Tell if we're allowed to process normal messages. /// Tell if we're allowed to process normal messages.
fn is_active(self) -> bool { fn is_active(self) -> bool {
match self { matches!(self, WebSocketState::Active)
WebSocketState::Active => true,
_ => false,
}
} }
/// Tell if we should process incoming data. Note that if we send a close frame /// 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 /// 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. /// close frame, so we should still pass those to client code, hence ClosedByUs is valid.
fn can_read(self) -> bool { fn can_read(self) -> bool {
match self { matches!(self, WebSocketState::Active | WebSocketState::ClosedByUs)
WebSocketState::Active | WebSocketState::ClosedByUs => true,
_ => false,
}
} }
/// Check if the state is active, return error if not. /// Check if the state is active, return error if not.

Loading…
Cancel
Save