Fix clippy warnings and deprecated settings

pull/223/head
Dominik Nakamura 3 years ago
parent c9c2f49305
commit 5e0fde5dc6
No known key found for this signature in database
GPG Key ID: E4C6A749B2491910
  1. 2
      rustfmt.toml
  2. 6
      src/buffer.rs
  3. 6
      src/protocol/frame/coding.rs
  4. 1
      src/protocol/frame/frame.rs
  5. 24
      src/protocol/message.rs

@ -4,4 +4,4 @@
# Break complex but short statements a bit less. # Break complex but short statements a bit less.
use_small_heuristics = "Max" use_small_heuristics = "Max"
merge_imports = true imports_granularity = "Crate"

@ -81,6 +81,12 @@ impl<const CHUNK_SIZE: usize> Buf for ReadBuffer<CHUNK_SIZE> {
} }
} }
impl<const CHUNK_SIZE: usize> Default for ReadBuffer<CHUNK_SIZE> {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

@ -71,14 +71,14 @@ impl fmt::Display for OpCode {
} }
} }
impl Into<u8> for OpCode { impl From<OpCode> for u8 {
fn into(self) -> u8 { fn from(code: OpCode) -> Self {
use self::{ use self::{
Control::{Close, Ping, Pong}, Control::{Close, Ping, Pong},
Data::{Binary, Continue, Text}, Data::{Binary, Continue, Text},
OpCode::*, OpCode::*,
}; };
match self { match code {
Data(Continue) => 0, Data(Continue) => 0,
Data(Text) => 1, Data(Text) => 1,
Data(Binary) => 2, Data(Binary) => 2,

@ -84,6 +84,7 @@ impl FrameHeader {
} }
/// Get the size of the header formatted with given payload length. /// Get the size of the header formatted with given payload length.
#[allow(clippy::len_without_is_empty)]
pub fn len(&self, length: u64) -> usize { pub fn len(&self, length: u64) -> usize {
2 + LengthFormat::for_length(length).extra_bytes() + if self.mask.is_some() { 4 } else { 0 } 2 + LengthFormat::for_length(length).extra_bytes() + if self.mask.is_some() { 4 } else { 0 }
} }

@ -1,5 +1,5 @@
use std::{ use std::{
convert::{AsRef, From, Into}, convert::{AsRef, From, Into, TryFrom},
fmt, fmt,
result::Result as StdResult, result::Result as StdResult,
str, str,
@ -270,32 +270,40 @@ impl Message {
} }
impl From<String> for Message { impl From<String> for Message {
fn from(string: String) -> Message { fn from(string: String) -> Self {
Message::text(string) Message::text(string)
} }
} }
impl<'s> From<&'s str> for Message { impl<'s> From<&'s str> for Message {
fn from(string: &'s str) -> Message { fn from(string: &'s str) -> Self {
Message::text(string) Message::text(string)
} }
} }
impl<'b> From<&'b [u8]> for Message { impl<'b> From<&'b [u8]> for Message {
fn from(data: &'b [u8]) -> Message { fn from(data: &'b [u8]) -> Self {
Message::binary(data) Message::binary(data)
} }
} }
impl From<Vec<u8>> for Message { impl From<Vec<u8>> for Message {
fn from(data: Vec<u8>) -> Message { fn from(data: Vec<u8>) -> Self {
Message::binary(data) Message::binary(data)
} }
} }
impl Into<Vec<u8>> for Message { impl From<Message> for Vec<u8> {
fn into(self) -> Vec<u8> { fn from(message: Message) -> Self {
self.into_data() message.into_data()
}
}
impl TryFrom<Message> for String {
type Error = Error;
fn try_from(value: Message) -> StdResult<Self, Self::Error> {
value.into_text()
} }
} }

Loading…
Cancel
Save