Clean up warnings

This commit is contained in:
Ryan Leckey 2019-09-03 07:17:17 -07:00
parent 7b992f2829
commit d36366ef41
24 changed files with 39 additions and 72 deletions

View File

@ -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",

View File

@ -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;

View File

@ -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<T: ByteOrder>(&mut self) -> io::Result<u64> {
Ok(match self.get_u8()? {
0xFC => self.get_u16::<T>()? as u64,
0xFD => self.get_u24::<T>()? as u64,
0xFE => self.get_u64::<T>()? as u64,
0xFC => u64::from(self.get_u16::<T>()?),
0xFD => u64::from(self.get_u24::<T>()?),
0xFE => self.get_u64::<T>()?,
// ? 0xFF => panic!("int<lenenc> unprocessable first byte 0xFF"),
value => value as u64,
value => u64::from(value),
})
}

View File

@ -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<u8> {
// Integer value is encoded in the next 8 bytes (9 bytes total)
self.push(0xFE);
self.put_u64::<T>(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::<T>(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::<T>(value as u16);

View File

@ -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();
}

View File

@ -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]

View File

@ -1,3 +1,6 @@
// TODO: Remove after acitve development
#![allow(ununsed)]
// mod backend;
// mod connection;
mod protocol;

View File

@ -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<DB>,
// 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,
}

View File

@ -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<TcpStream>,

View File

@ -28,7 +28,7 @@ mod tests {
#[tokio::test]
async fn it_pings() {
let mut conn = Connection::<Postgres>::establish(DATABASE_URL)
let conn = Connection::<Postgres>::establish(DATABASE_URL)
.await
.unwrap();

View File

@ -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).

View File

@ -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() {

View File

@ -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";

View File

@ -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() {

View File

@ -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)]

View File

@ -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";

View File

@ -13,7 +13,7 @@ impl Decode for ParameterDescription {
let cnt = buf.get_u16::<NetworkEndian>()? as usize;
let mut ids = Vec::with_capacity(cnt);
for i in 0..cnt {
for _ in 0..cnt {
ids.push(buf.get_u32::<NetworkEndian>()?);
}
@ -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() {

View File

@ -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())

View File

@ -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";

View File

@ -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";

View File

@ -1,4 +1,4 @@
use super::{protocol, Postgres, PostgresRawConnection};
use super::Postgres;
use crate::{
io::BufMut,
query::QueryParameters,

View File

@ -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;

View File

@ -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<DB>(query: &str) -> SqlQuery<'_, DB>
where
DB: Backend,
{

View File

@ -1,5 +1,3 @@
use crate::backend::Backend;
/// Information about how a backend stores metadata about
/// given SQL types.
pub trait TypeMetadata {