From e080f1ecdbc9737a0656f803b491acad01039752 Mon Sep 17 00:00:00 2001 From: Joey Sacchini Date: Thu, 3 Dec 2020 16:44:02 -0500 Subject: cargo fmt --- src/cfb8.rs | 8 ++++---- src/connection.rs | 2 +- src/reader.rs | 23 +++++++++++++++++------ src/tcp.rs | 6 +++--- src/wrapper.rs | 1 - src/writer.rs | 24 ++++++++++++------------ 6 files changed, 37 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/cfb8.rs b/src/cfb8.rs index 1348f73..3b15e0b 100644 --- a/src/cfb8.rs +++ b/src/cfb8.rs @@ -2,9 +2,9 @@ use aes::{ cipher::{consts::U16, generic_array::GenericArray, BlockCipherMut, NewBlockCipher}, Aes128, }; -use thiserror::Error; #[cfg(feature = "backtrace")] use std::backtrace::Backtrace; +use thiserror::Error; pub type CraftCipherResult = Result; @@ -26,7 +26,7 @@ pub enum CipherError { size: usize, component: CipherComponent, #[cfg(feature = "backtrace")] - backtrace: Backtrace + backtrace: Backtrace, }, } @@ -36,14 +36,14 @@ impl CipherError { component, size, #[cfg(feature = "backtrace")] - backtrace: Backtrace::capture() + backtrace: Backtrace::capture(), } } fn already_enabled() -> Self { CipherError::AlreadyEnabled { #[cfg(feature = "backtrace")] - backtrace: Backtrace::capture() + backtrace: Backtrace::capture(), } } } diff --git a/src/connection.rs b/src/connection.rs index c061c85..8de42f3 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -8,7 +8,7 @@ use mcproto_rs::protocol::{Packet, RawPacket, State}; #[cfg(any(feature = "futures-io", feature = "tokio-io"))] use { crate::{reader::CraftAsyncReader, writer::CraftAsyncWriter}, - async_trait::async_trait + async_trait::async_trait, }; pub struct CraftConnection { diff --git a/src/reader.rs b/src/reader.rs index 55edaee..271e0b7 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -234,14 +234,16 @@ where #[cfg(any(feature = "futures-io", feature = "tokio-io"))] pub trait IntoBufferedAsyncRead { - type Target: AsyncReadExact; fn into_buffered(self, capacity: usize) -> Self::Target; } #[cfg(all(feature = "futures-io", not(feature = "tokio-io")))] -impl IntoBufferedAsyncRead for R where R: futures::io::AsyncRead + Send + Sync + Unpin { +impl IntoBufferedAsyncRead for R +where + R: futures::io::AsyncRead + Send + Sync + Unpin, +{ type Target = futures::io::BufReader; fn into_buffered(self, capacity: usize) -> Self::Target { @@ -250,7 +252,10 @@ impl IntoBufferedAsyncRead for R where R: futures::io::AsyncRead + Send + Syn } #[cfg(feature = "tokio-io")] -impl IntoBufferedAsyncRead for R where R: tokio::io::AsyncRead + Send + Sync + Unpin { +impl IntoBufferedAsyncRead for R +where + R: tokio::io::AsyncRead + Send + Sync + Unpin, +{ type Target = tokio::io::BufReader; fn into_buffered(self, capacity: usize) -> Self::Target { @@ -266,7 +271,10 @@ pub trait AsyncReadExact: Unpin + Sync + Send { #[cfg(all(feature = "futures-io", not(feature = "tokio-io")))] #[async_trait] -impl AsyncReadExact for R where R: futures::AsyncReadExt + Unpin + Sync + Send { +impl AsyncReadExact for R +where + R: futures::AsyncReadExt + Unpin + Sync + Send, +{ async fn read_exact(&mut self, to: &mut [u8]) -> Result<(), io::Error> { futures::AsyncReadExt::read_exact(self, to).await } @@ -274,7 +282,10 @@ impl AsyncReadExact for R where R: futures::AsyncReadExt + Unpin + Sync + Sen #[cfg(feature = "tokio-io")] #[async_trait] -impl AsyncReadExact for R where R: tokio::io::AsyncRead + Unpin + Sync + Send { +impl AsyncReadExact for R +where + R: tokio::io::AsyncRead + Unpin + Sync + Send, +{ async fn read_exact(&mut self, to: &mut [u8]) -> Result<(), io::Error> { tokio::io::AsyncReadExt::read_exact(self, to).await?; Ok(()) @@ -394,7 +405,7 @@ impl CraftReader { } #[cfg(feature = "encryption")] -fn handle_decryption(cipher: Option<&mut CraftCipher>, buf: &mut[u8]) { +fn handle_decryption(cipher: Option<&mut CraftCipher>, buf: &mut [u8]) { if let Some(encryption) = cipher { encryption.decrypt(buf); } diff --git a/src/tcp.rs b/src/tcp.rs index 37a94c5..bd88885 100644 --- a/src/tcp.rs +++ b/src/tcp.rs @@ -6,7 +6,7 @@ use std::io::BufReader as StdBufReader; use std::net::TcpStream; #[cfg(any(feature = "futures-io", feature = "tokio-io"))] -use crate::{CraftAsyncWriter, CraftAsyncReader, IntoBufferedAsyncRead}; +use crate::{CraftAsyncReader, CraftAsyncWriter, IntoBufferedAsyncRead}; pub const BUF_SIZE: usize = 8192; @@ -51,7 +51,7 @@ where { pub fn from_unbuffered_async(tuple: (U, W), read_direction: PacketDirection) -> Self where - U: IntoBufferedAsyncRead, + U: IntoBufferedAsyncRead, { Self::from_unbuffered_async_with_state(tuple, read_direction, State::Handshaking) } @@ -62,7 +62,7 @@ where state: State, ) -> Self where - U: IntoBufferedAsyncRead, + U: IntoBufferedAsyncRead, { let (ru, writer) = tuple; let reader = ru.into_buffered(BUF_SIZE); diff --git a/src/wrapper.rs b/src/wrapper.rs index 71ff7da..0920ad4 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -7,7 +7,6 @@ pub trait CraftWrapper { } pub trait CraftIo { - fn set_state(&mut self, next: State); #[cfg(feature = "compression")] diff --git a/src/writer.rs b/src/writer.rs index acea3f3..6488534 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -36,7 +36,7 @@ pub enum WriteError { #[cfg(feature = "compression")] CompressBufError { #[cfg(feature = "backtrace")] - backtrace: Backtrace + backtrace: Backtrace, }, #[error("io error while writing data")] IoFail { @@ -199,7 +199,10 @@ pub trait AsyncWriteAll: Unpin + Send + Sync { #[cfg(all(feature = "futures-io", not(feature = "tokio-io")))] #[async_trait] -impl AsyncWriteAll for W where W: futures::AsyncWrite + Unpin + Send + Sync { +impl AsyncWriteAll for W +where + W: futures::AsyncWrite + Unpin + Send + Sync, +{ async fn write_all(&mut self, data: &[u8]) -> Result<(), std::io::Error> { futures::AsyncWriteExt::write_all(self, data).await?; Ok(()) @@ -208,7 +211,10 @@ impl AsyncWriteAll for W where W: futures::AsyncWrite + Unpin + Send + Sync { #[cfg(feature = "tokio-io")] #[async_trait] -impl AsyncWriteAll for W where W: tokio::io::AsyncWrite + Unpin + Send + Sync { +impl AsyncWriteAll for W +where + W: tokio::io::AsyncWrite + Unpin + Send + Sync, +{ async fn write_all(&mut self, data: &[u8]) -> Result<(), std::io::Error> { tokio::io::AsyncWriteExt::write_all(self, data).await?; Ok(()) @@ -369,11 +375,7 @@ impl CraftWriter { } } -fn prepare_packet_normally( - buf: &mut [u8], - body_size: usize, -) -> WriteResult<&mut [u8]> -{ +fn prepare_packet_normally(buf: &mut [u8], body_size: usize) -> WriteResult<&mut [u8]> { let packet_len_target = &mut buf[VAR_INT_BUF_SIZE..HEADER_OFFSET]; let mut packet_len_serializer = SliceSerializer::create(packet_len_target); VarInt(body_size as i32) @@ -398,8 +400,7 @@ fn prepare_packet_compressed<'a>( body_size: usize, ) -> WriteResult<&'a mut [u8]> { let compressed_size = compress(buf, compress_buf, HEADER_OFFSET)?.len(); - let compress_buf = - get_sized_buf(compress_buf, 0, compressed_size + HEADER_OFFSET); + let compress_buf = get_sized_buf(compress_buf, 0, compressed_size + HEADER_OFFSET); let data_len_target = &mut compress_buf[VAR_INT_BUF_SIZE..HEADER_OFFSET]; let mut data_len_serializer = SliceSerializer::create(data_len_target); @@ -437,8 +438,7 @@ fn prepare_packet_compressed<'a>( fn prepare_packet_compressed_below_threshold( buf: &mut [u8], body_size: usize, -) -> WriteResult<&mut [u8]> -{ +) -> WriteResult<&mut [u8]> { let packet_len_start_at = VAR_INT_BUF_SIZE - 1; let packet_len_target = &mut buf[packet_len_start_at..HEADER_OFFSET - 1]; let mut packet_len_serializer = SliceSerializer::create(packet_len_target); -- cgit