Fix various clippy warnings

pull/93/head
Sebastian Dröge 5 years ago
parent 7a4779b6f6
commit 88760b8b59
  1. 4
      examples/autobahn-client.rs
  2. 6
      src/handshake/client.rs
  3. 6
      src/handshake/headers.rs
  4. 4
      src/handshake/server.rs
  5. 2
      src/protocol/message.rs
  6. 6
      src/protocol/mod.rs

@ -3,7 +3,7 @@ use url::Url;
use tungstenite::{connect, Error, Message, Result}; use tungstenite::{connect, Error, Message, Result};
const AGENT: &'static str = "Tungstenite"; const AGENT: &str = "Tungstenite";
fn get_case_count() -> Result<u32> { fn get_case_count() -> Result<u32> {
let (mut socket, _) = connect(Url::parse("ws://localhost:9001/getCaseCount").unwrap())?; let (mut socket, _) = connect(Url::parse("ws://localhost:9001/getCaseCount").unwrap())?;
@ -47,7 +47,7 @@ fn main() {
let total = get_case_count().unwrap(); let total = get_case_count().unwrap();
for case in 1..(total + 1) { for case in 1..=total {
if let Err(e) = run_test(case) { if let Err(e) = run_test(case) {
match e { match e {
Error::Protocol(_) => {} Error::Protocol(_) => {}

@ -257,13 +257,13 @@ mod tests {
assert_eq!(k2.len(), 24); assert_eq!(k2.len(), 24);
assert!(k1.ends_with("==")); assert!(k1.ends_with("=="));
assert!(k2.ends_with("==")); assert!(k2.ends_with("=="));
assert!(k1[..22].find("=").is_none()); assert!(k1[..22].find('=').is_none());
assert!(k2[..22].find("=").is_none()); assert!(k2[..22].find('=').is_none());
} }
#[test] #[test]
fn response_parsing() { fn response_parsing() {
const DATA: &'static [u8] = b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"; const DATA: &[u8] = b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
let (_, resp) = Response::try_parse(DATA).unwrap().unwrap(); let (_, resp) = Response::try_parse(DATA).unwrap().unwrap();
assert_eq!(resp.status(), http::StatusCode::OK); assert_eq!(resp.status(), http::StatusCode::OK);
assert_eq!( assert_eq!(

@ -48,7 +48,7 @@ mod tests {
#[test] #[test]
fn headers() { fn headers() {
const DATA: &'static [u8] = b"Host: foo.com\r\n\ const DATA: &[u8] = b"Host: foo.com\r\n\
Connection: Upgrade\r\n\ Connection: Upgrade\r\n\
Upgrade: websocket\r\n\ Upgrade: websocket\r\n\
\r\n"; \r\n";
@ -60,7 +60,7 @@ mod tests {
#[test] #[test]
fn headers_iter() { fn headers_iter() {
const DATA: &'static [u8] = b"Host: foo.com\r\n\ const DATA: &[u8] = b"Host: foo.com\r\n\
Sec-WebSocket-Extensions: permessage-deflate\r\n\ Sec-WebSocket-Extensions: permessage-deflate\r\n\
Connection: Upgrade\r\n\ Connection: Upgrade\r\n\
Sec-WebSocket-ExtenSIONS: permessage-unknown\r\n\ Sec-WebSocket-ExtenSIONS: permessage-unknown\r\n\
@ -75,7 +75,7 @@ mod tests {
#[test] #[test]
fn headers_incomplete() { fn headers_incomplete() {
const DATA: &'static [u8] = b"Host: foo.com\r\n\ const DATA: &[u8] = b"Host: foo.com\r\n\
Connection: Upgrade\r\n\ Connection: Upgrade\r\n\
Upgrade: websocket\r\n"; Upgrade: websocket\r\n";
let hdr = HeaderMap::try_parse(DATA).unwrap(); let hdr = HeaderMap::try_parse(DATA).unwrap();

@ -295,7 +295,7 @@ mod tests {
#[test] #[test]
fn request_parsing() { fn request_parsing() {
const DATA: &'static [u8] = b"GET /script.ws HTTP/1.1\r\nHost: foo.com\r\n\r\n"; const DATA: &[u8] = b"GET /script.ws HTTP/1.1\r\nHost: foo.com\r\n\r\n";
let (_, req) = Request::try_parse(DATA).unwrap().unwrap(); let (_, req) = Request::try_parse(DATA).unwrap().unwrap();
assert_eq!(req.uri().path(), "/script.ws"); assert_eq!(req.uri().path(), "/script.ws");
assert_eq!(req.headers().get("Host").unwrap(), &b"foo.com"[..]); assert_eq!(req.headers().get("Host").unwrap(), &b"foo.com"[..]);
@ -303,7 +303,7 @@ mod tests {
#[test] #[test]
fn request_replying() { fn request_replying() {
const DATA: &'static [u8] = b"\ const DATA: &[u8] = b"\
GET /script.ws HTTP/1.1\r\n\ GET /script.ws HTTP/1.1\r\n\
Host: foo.com\r\n\ Host: foo.com\r\n\
Connection: upgrade\r\n\ Connection: upgrade\r\n\

@ -343,7 +343,7 @@ mod tests {
#[test] #[test]
fn display() { fn display() {
let t = Message::text(format!("test")); let t = Message::text("test".to_owned());
assert_eq!(t.to_string(), "test".to_owned()); assert_eq!(t.to_string(), "test".to_owned());
let bin = Message::binary(vec![0, 1, 3, 4, 241]); let bin = Message::binary(vec![0, 1, 3, 4, 241]);

@ -592,7 +592,7 @@ 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 { match self {
WebSocketState::Active => true, WebSocketState::Active => true,
_ => false, _ => false,
@ -602,7 +602,7 @@ impl WebSocketState {
/// 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 { match self {
WebSocketState::Active | WebSocketState::ClosedByUs => true, WebSocketState::Active | WebSocketState::ClosedByUs => true,
_ => false, _ => false,
@ -610,7 +610,7 @@ impl WebSocketState {
} }
/// Check if the state is active, return error if not. /// Check if the state is active, return error if not.
fn check_active(&self) -> Result<()> { fn check_active(self) -> Result<()> {
match self { match self {
WebSocketState::Terminated => Err(Error::AlreadyClosed), WebSocketState::Terminated => Err(Error::AlreadyClosed),
_ => Ok(()), _ => Ok(()),

Loading…
Cancel
Save