Fix clippy warnings and deprecated settings

This commit is contained in:
Dominik Nakamura 2021-07-21 10:43:44 +09:00
parent c9c2f49305
commit 5e0fde5dc6
No known key found for this signature in database
GPG Key ID: E4C6A749B2491910
5 changed files with 27 additions and 12 deletions

View File

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

View File

@ -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)]
mod tests {
use super::*;

View File

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

View File

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

View File

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