diff --git a/src/connection.rs b/src/connection.rs index 343473af..d91a0c6d 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -11,7 +11,6 @@ use futures_channel::oneshot::{channel, Sender}; use futures_core::{future::BoxFuture, stream::BoxStream}; use futures_util::{stream::StreamExt, TryFutureExt}; use std::{ - io, ops::{Deref, DerefMut}, sync::{ atomic::{AtomicBool, Ordering}, @@ -38,10 +37,10 @@ pub trait RawConnection: Send { /// and clean up not fully closed connections. /// /// It is safe to close an already closed connection. - fn close<'c>(&'c mut self) -> BoxFuture<'c, Result<(), Error>>; + fn close(&mut self) -> BoxFuture<'_, Result<(), Error>>; /// Verifies a connection to the database is still alive. - fn ping<'c>(&'c mut self) -> BoxFuture<'c, Result<(), Error>> { + fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>> { Box::pin( self.execute( "SELECT 1", diff --git a/src/executor.rs b/src/executor.rs index ef6cca3c..289ef7c2 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -1,11 +1,5 @@ -use crate::{ - backend::Backend, - error::Error, - query::{IntoQueryParameters, QueryParameters}, - row::FromSqlRow, -}; +use crate::{backend::Backend, error::Error, query::IntoQueryParameters, row::FromSqlRow}; use futures_core::{future::BoxFuture, stream::BoxStream}; -use std::io; pub trait Executor: Send { type Backend: Backend; diff --git a/src/io/buf.rs b/src/io/buf.rs index 566bacfb..76b7f416 100644 --- a/src/io/buf.rs +++ b/src/io/buf.rs @@ -1,6 +1,6 @@ use byteorder::ByteOrder; use memchr::memchr; -use std::{convert::TryInto, io, mem::size_of, str}; +use std::{io, str}; pub trait Buf { fn advance(&mut self, cnt: usize); @@ -91,11 +91,11 @@ impl<'a> Buf for &'a [u8] { fn get_uint_lenenc(&mut self) -> io::Result { Ok(match self.get_u8()? { - 0xFC => self.get_u16::()? as u64, - 0xFD => self.get_u24::()? as u64, - 0xFE => self.get_u64::()? as u64, + 0xFC => u64::from(self.get_u16::()?), + 0xFD => u64::from(self.get_u24::()?), + 0xFE => self.get_u64::()?, // ? 0xFF => panic!("int unprocessable first byte 0xFF"), - value => value as u64, + value => u64::from(value), }) } diff --git a/src/io/buf_mut.rs b/src/io/buf_mut.rs index f44a30c3..c1fb159f 100644 --- a/src/io/buf_mut.rs +++ b/src/io/buf_mut.rs @@ -1,6 +1,5 @@ use byteorder::ByteOrder; -use memchr::memchr; -use std::{io, mem::size_of, str, u16, u32, u8}; +use std::{str, u16, u32, u8}; pub trait BufMut { fn advance(&mut self, cnt: usize); @@ -82,11 +81,11 @@ impl BufMut for Vec { // Integer value is encoded in the next 8 bytes (9 bytes total) self.push(0xFE); self.put_u64::(value); - } else if value > u16::MAX as _ { + } else if value > u64::from(u16::MAX) { // Integer value is encoded in the next 3 bytes (4 bytes total) self.push(0xFD); self.put_u24::(value as u32); - } else if value > u8::MAX as _ { + } else if value > u64::from(u8::MAX) { // Integer value is encoded in the next 2 bytes (3 bytes total) self.push(0xFC); self.put_u16::(value as u16); diff --git a/src/io/buf_stream.rs b/src/io/buf_stream.rs index b90a78e5..5d7775e8 100644 --- a/src/io/buf_stream.rs +++ b/src/io/buf_stream.rs @@ -23,7 +23,7 @@ where Self { stream, stream_eof: false, - wbuf: Vec::with_capacity(1 * 1024), + wbuf: Vec::with_capacity(1024), rbuf: BytesMut::with_capacity(8 * 1024), } } @@ -39,7 +39,7 @@ where #[inline] pub async fn flush(&mut self) -> io::Result<()> { - if self.wbuf.len() > 0 { + if !self.wbuf.is_empty() { self.stream.write_all(&self.wbuf).await?; self.wbuf.clear(); } diff --git a/src/lib.rs b/src/lib.rs index b1cf132d..2a959f5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,18 +1,14 @@ -#![cfg_attr(test, feature(test))] -#![allow(clippy::needless_lifetimes)] -#![allow(unused)] - -#[cfg(test)] -extern crate test; - #[macro_use] mod macros; +#[cfg(any(feature = "postgres", feature = "mariadb"))] #[macro_use] mod io; mod backend; pub mod deserialize; + +#[cfg(any(feature = "postgres", feature = "mariadb"))] mod url; #[macro_use] diff --git a/src/mariadb/mod.rs b/src/mariadb/mod.rs index 2b46ff09..586c6720 100644 --- a/src/mariadb/mod.rs +++ b/src/mariadb/mod.rs @@ -1,3 +1,6 @@ +// TODO: Remove after acitve development +#![allow(ununsed)] + // mod backend; // mod connection; mod protocol; diff --git a/src/pool.rs b/src/pool.rs index bcf73470..18c954ff 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -1,17 +1,12 @@ use crate::{ - backend::Backend, - connection::RawConnection, - error::Error, - executor::Executor, - query::{IntoQueryParameters, QueryParameters}, - row::FromSqlRow, + backend::Backend, connection::RawConnection, error::Error, executor::Executor, + query::IntoQueryParameters, row::FromSqlRow, }; use crossbeam_queue::{ArrayQueue, SegQueue}; use futures_channel::oneshot; use futures_core::{future::BoxFuture, stream::BoxStream}; use futures_util::stream::StreamExt; use std::{ - io, ops::{Deref, DerefMut}, sync::{ atomic::{AtomicUsize, Ordering}, @@ -244,6 +239,8 @@ where DB: Backend, { live: Live, + // TODO: Implement idle connection timeouts + #[allow(unused)] since: Instant, } @@ -252,5 +249,7 @@ where DB: Backend, { raw: DB::RawConnection, + // TODO: Implement live connection timeouts + #[allow(unused)] since: Instant, } diff --git a/src/postgres/connection.rs b/src/postgres/connection.rs index 7bbe633c..fddc298f 100644 --- a/src/postgres/connection.rs +++ b/src/postgres/connection.rs @@ -4,22 +4,13 @@ use super::{ }; use crate::{ connection::RawConnection, - error::Error, io::{Buf, BufStream}, - query::QueryParameters, url::Url, }; use byteorder::NetworkEndian; use futures_core::{future::BoxFuture, stream::BoxStream}; -use std::{ - io, - net::{IpAddr, Shutdown, SocketAddr}, - sync::atomic::{AtomicU64, Ordering}, -}; -use tokio::{ - io::{AsyncReadExt, AsyncWriteExt}, - net::TcpStream, -}; +use std::io; +use tokio::net::TcpStream; pub struct PostgresRawConnection { stream: BufStream, diff --git a/src/postgres/mod.rs b/src/postgres/mod.rs index 33a4a0f7..40e13925 100644 --- a/src/postgres/mod.rs +++ b/src/postgres/mod.rs @@ -28,7 +28,7 @@ mod tests { #[tokio::test] async fn it_pings() { - let mut conn = Connection::::establish(DATABASE_URL) + let conn = Connection::::establish(DATABASE_URL) .await .unwrap(); diff --git a/src/postgres/protocol/bind.rs b/src/postgres/protocol/bind.rs index 5ed47d4a..b48ad9c8 100644 --- a/src/postgres/protocol/bind.rs +++ b/src/postgres/protocol/bind.rs @@ -1,6 +1,6 @@ use super::Encode; use crate::io::BufMut; -use byteorder::{BigEndian, ByteOrder, NetworkEndian}; +use byteorder::{ByteOrder, NetworkEndian}; pub struct Bind<'a> { /// The name of the destination portal (an empty string selects the unnamed portal). diff --git a/src/postgres/protocol/close.rs b/src/postgres/protocol/close.rs index 709b6bc2..6fc93b3c 100644 --- a/src/postgres/protocol/close.rs +++ b/src/postgres/protocol/close.rs @@ -34,7 +34,7 @@ impl Encode for Close<'_> { #[cfg(test)] mod test { - use super::{BufMut, Close, CloseKind, Encode}; + use super::{Close, CloseKind, Encode}; #[test] fn it_encodes_close_portal() { diff --git a/src/postgres/protocol/data_row.rs b/src/postgres/protocol/data_row.rs index abd96eb7..a7c356e4 100644 --- a/src/postgres/protocol/data_row.rs +++ b/src/postgres/protocol/data_row.rs @@ -82,7 +82,6 @@ impl Debug for DataRow { #[cfg(test)] mod tests { use super::{DataRow, Decode}; - use std::io; const DATA_ROW: &[u8] = b"\0\x03\0\0\0\x011\0\0\0\x012\0\0\0\x013"; diff --git a/src/postgres/protocol/describe.rs b/src/postgres/protocol/describe.rs index a290426a..6df51885 100644 --- a/src/postgres/protocol/describe.rs +++ b/src/postgres/protocol/describe.rs @@ -31,7 +31,7 @@ impl Encode for Describe<'_> { #[cfg(test)] mod test { - use super::{BufMut, Describe, DescribeKind, Encode}; + use super::{Describe, DescribeKind, Encode}; #[test] fn it_encodes_describe_portal() { diff --git a/src/postgres/protocol/message.rs b/src/postgres/protocol/message.rs index c1df45da..2a854723 100644 --- a/src/postgres/protocol/message.rs +++ b/src/postgres/protocol/message.rs @@ -1,10 +1,7 @@ use super::{ - Authentication, BackendKeyData, CommandComplete, DataRow, Decode, NotificationResponse, + Authentication, BackendKeyData, CommandComplete, DataRow, NotificationResponse, ParameterDescription, ParameterStatus, ReadyForQuery, Response, }; -use byteorder::{BigEndian, ByteOrder}; -use bytes::BytesMut; -use std::io; #[derive(Debug)] #[repr(u8)] diff --git a/src/postgres/protocol/notification_response.rs b/src/postgres/protocol/notification_response.rs index cef5d34a..2aa07494 100644 --- a/src/postgres/protocol/notification_response.rs +++ b/src/postgres/protocol/notification_response.rs @@ -66,7 +66,6 @@ impl Decode for NotificationResponse { #[cfg(test)] mod tests { use super::{Decode, NotificationResponse}; - use std::io; const NOTIFICATION_RESPONSE: &[u8] = b"\x34\x20\x10\x02TEST-CHANNEL\0THIS IS A TEST\0"; diff --git a/src/postgres/protocol/parameter_description.rs b/src/postgres/protocol/parameter_description.rs index 3b3328ec..ef122b55 100644 --- a/src/postgres/protocol/parameter_description.rs +++ b/src/postgres/protocol/parameter_description.rs @@ -13,7 +13,7 @@ impl Decode for ParameterDescription { let cnt = buf.get_u16::()? as usize; let mut ids = Vec::with_capacity(cnt); - for i in 0..cnt { + for _ in 0..cnt { ids.push(buf.get_u32::()?); } @@ -26,7 +26,6 @@ impl Decode for ParameterDescription { #[cfg(test)] mod test { use super::{Decode, ParameterDescription}; - use std::io; #[test] fn it_decodes_parameter_description() { diff --git a/src/postgres/protocol/parameter_status.rs b/src/postgres/protocol/parameter_status.rs index b80afae1..3815c7f7 100644 --- a/src/postgres/protocol/parameter_status.rs +++ b/src/postgres/protocol/parameter_status.rs @@ -49,7 +49,7 @@ impl Decode for ParameterStatus { } } -impl fmt::Debug for ParameterStatus { +impl Debug for ParameterStatus { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("ParameterStatus") .field("name", &self.name()) diff --git a/src/postgres/protocol/query.rs b/src/postgres/protocol/query.rs index 39a64687..9938f570 100644 --- a/src/postgres/protocol/query.rs +++ b/src/postgres/protocol/query.rs @@ -17,7 +17,7 @@ impl Encode for Query<'_> { #[cfg(test)] mod tests { - use super::{BufMut, Encode, Query}; + use super::{Encode, Query}; const QUERY_SELECT_1: &[u8] = b"Q\0\0\0\rSELECT 1\0"; diff --git a/src/postgres/protocol/startup_message.rs b/src/postgres/protocol/startup_message.rs index b49f796f..2c29c6e1 100644 --- a/src/postgres/protocol/startup_message.rs +++ b/src/postgres/protocol/startup_message.rs @@ -29,7 +29,7 @@ impl Encode for StartupMessage<'_> { #[cfg(test)] mod tests { - use super::{BufMut, Encode, StartupMessage}; + use super::{Encode, StartupMessage}; const STARTUP_MESSAGE: &[u8] = b"\0\0\0)\0\x03\0\0user\0postgres\0database\0postgres\0\0"; diff --git a/src/postgres/query.rs b/src/postgres/query.rs index 44f6b94b..cbbb6304 100644 --- a/src/postgres/query.rs +++ b/src/postgres/query.rs @@ -1,4 +1,4 @@ -use super::{protocol, Postgres, PostgresRawConnection}; +use super::Postgres; use crate::{ io::BufMut, query::QueryParameters, diff --git a/src/query.rs b/src/query.rs index 0a864c46..6efbffd2 100644 --- a/src/query.rs +++ b/src/query.rs @@ -1,9 +1,4 @@ -use crate::{ - backend::Backend, error::Error, executor::Executor, row::FromSqlRow, serialize::ToSql, - types::HasSqlType, -}; -use futures_core::{future::BoxFuture, stream::BoxStream}; -use std::io; +use crate::{backend::Backend, serialize::ToSql, types::HasSqlType}; pub trait QueryParameters: Send { type Backend: Backend; diff --git a/src/sql.rs b/src/sql.rs index 79fad1e0..24128049 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -3,7 +3,6 @@ use crate::{ serialize::ToSql, types::HasSqlType, }; use futures_core::{future::BoxFuture, stream::BoxStream}; -use std::io; pub struct SqlQuery<'q, DB> where @@ -72,7 +71,7 @@ where /// Construct a full SQL query using raw SQL. #[inline] -pub fn query<'q, DB>(query: &'q str) -> SqlQuery<'q, DB> +pub fn query(query: &str) -> SqlQuery<'_, DB> where DB: Backend, { diff --git a/src/types.rs b/src/types.rs index 23105b3b..f3210b93 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,5 +1,3 @@ -use crate::backend::Backend; - /// Information about how a backend stores metadata about /// given SQL types. pub trait TypeMetadata {