remove unused imports

This commit is contained in:
Ryan Leckey 2020-03-11 02:29:20 -07:00
parent 6924b4fe6d
commit c14338d329
16 changed files with 39 additions and 64 deletions

View File

@ -32,6 +32,7 @@ pub trait Connect: Connection {
} }
mod internal { mod internal {
#[allow(dead_code)]
pub enum MaybeOwnedConnection<'c, C> pub enum MaybeOwnedConnection<'c, C>
where where
C: super::Connect, C: super::Connect,
@ -40,6 +41,7 @@ mod internal {
Owned(super::PoolConnection<C>), Owned(super::PoolConnection<C>),
} }
#[allow(dead_code)]
pub enum ConnectionSource<'c, C> pub enum ConnectionSource<'c, C>
where where
C: super::Connect, C: super::Connect,
@ -55,6 +57,7 @@ impl<'c, C> ConnectionSource<'c, C>
where where
C: Connect, C: Connect,
{ {
#[allow(dead_code)]
pub(crate) async fn resolve_by_ref(&mut self) -> crate::Result<&'_ mut C> { pub(crate) async fn resolve_by_ref(&mut self) -> crate::Result<&'_ mut C> {
if let ConnectionSource::Pool(pool) = self { if let ConnectionSource::Pool(pool) = self {
*self = *self =

View File

@ -53,6 +53,7 @@ pub enum Error {
} }
impl Error { impl Error {
#[allow(dead_code)]
pub(crate) fn decode<E>(err: E) -> Self pub(crate) fn decode<E>(err: E) -> Self
where where
E: StdError + Send + Sync + 'static, E: StdError + Send + Sync + 'static,

View File

@ -3,7 +3,6 @@
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#![recursion_limit = "512"] #![recursion_limit = "512"]
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(unused)]
#[macro_use] #[macro_use]
pub mod error; pub mod error;

View File

@ -1,25 +1,20 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryInto; use std::convert::TryInto;
use std::io; use std::ops::Range;
use std::sync::Arc;
use byteorder::{ByteOrder, LittleEndian};
use futures_core::future::BoxFuture; use futures_core::future::BoxFuture;
use sha1::Sha1; use sha1::Sha1;
use std::net::Shutdown;
use crate::connection::{Connect, Connection}; use crate::connection::{Connect, Connection};
use crate::io::{Buf, BufMut, BufStream, MaybeTlsStream};
use crate::mysql::error::MySqlError;
use crate::mysql::protocol::{ use crate::mysql::protocol::{
AuthPlugin, AuthSwitch, Capabilities, ComPing, Decode, Encode, EofPacket, ErrPacket, Handshake, AuthPlugin, AuthSwitch, Capabilities, ComPing, Decode, Handshake,
HandshakeResponse, OkPacket, SslRequest, HandshakeResponse,
}; };
use crate::mysql::stream::MySqlStream; use crate::mysql::stream::MySqlStream;
use crate::mysql::util::xor_eq; use crate::mysql::util::xor_eq;
use crate::mysql::{rsa, tls}; use crate::mysql::{rsa, tls};
use crate::executor::Executor;
use crate::url::Url; use crate::url::Url;
use std::ops::Range;
// Size before a packet is split // Size before a packet is split
pub(super) const MAX_PACKET_SIZE: u32 = 1024; pub(super) const MAX_PACKET_SIZE: u32 = 1024;
@ -191,7 +186,6 @@ async fn establish(stream: &mut MySqlStream, url: &Url) -> crate::Result<()> {
loop { loop {
// After sending the handshake response with our assumed auth method the server // After sending the handshake response with our assumed auth method the server
// will send OK, fail, or tell us to change auth methods // will send OK, fail, or tell us to change auth methods
let capabilities = stream.capabilities;
let packet = stream.receive().await?; let packet = stream.receive().await?;
match packet[0] { match packet[0] {
@ -238,7 +232,7 @@ async fn establish(stream: &mut MySqlStream, url: &Url) -> crate::Result<()> {
} }
} }
unk => { _ => {
return stream.handle_unexpected(); return stream.handle_unexpected();
} }
} }

View File

@ -60,8 +60,6 @@ impl<'c, 'q> Cursor<'c, 'q> for MySqlCursor<'c, 'q> {
async fn next<'a, 'c: 'a, 'q: 'a>( async fn next<'a, 'c: 'a, 'q: 'a>(
cursor: &'a mut MySqlCursor<'c, 'q>, cursor: &'a mut MySqlCursor<'c, 'q>,
) -> crate::Result<Option<MySqlRow<'a>>> { ) -> crate::Result<Option<MySqlRow<'a>>> {
println!("[cursor::next]");
let mut conn = cursor.source.resolve_by_ref().await?; let mut conn = cursor.source.resolve_by_ref().await?;
// The first time [next] is called we need to actually execute our // The first time [next] is called we need to actually execute our
@ -79,8 +77,7 @@ async fn next<'a, 'c: 'a, 'q: 'a>(
}; };
loop { loop {
let mut packet_id = conn.stream.receive().await?[0]; let packet_id = conn.stream.receive().await?[0];
println!("[cursor::next/iter] {:x}", packet_id);
match packet_id { match packet_id {
// OK or EOF packet // OK or EOF packet
0x00 | 0xFE 0x00 | 0xFE

View File

@ -1,26 +1,22 @@
use std::collections::HashMap;
use std::sync::Arc;
use futures_core::future::BoxFuture; use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use crate::cursor::Cursor; use crate::cursor::Cursor;
use crate::describe::{Column, Describe}; use crate::describe::{Column, Describe};
use crate::executor::{Execute, Executor, RefExecutor}; use crate::executor::{Execute, Executor, RefExecutor};
use crate::mysql::protocol::{ use crate::mysql::protocol::{
Status, Status,
self, Capabilities, ColumnCount, ColumnDefinition, ComQuery, ComStmtExecute, ComStmtPrepare, self, ColumnDefinition, ComQuery, ComStmtExecute, ComStmtPrepare,
ComStmtPrepareOk, Decode, EofPacket, ErrPacket, FieldFlags, OkPacket, Row, TypeId, ComStmtPrepareOk, Decode, FieldFlags,
}; };
use crate::mysql::{ use crate::mysql::{
MySql, MySqlArguments, MySqlConnection, MySqlCursor, MySqlError, MySqlRow, MySqlTypeInfo, MySql, MySqlArguments, MySqlCursor, MySqlTypeInfo,
}; };
impl super::MySqlConnection { impl super::MySqlConnection {
async fn wait_until_ready(&mut self) -> crate::Result<()> { async fn wait_until_ready(&mut self) -> crate::Result<()> {
if !self.is_ready { if !self.is_ready {
loop { loop {
let mut packet_id = self.stream.receive().await?[0]; let packet_id = self.stream.receive().await?[0];
match packet_id { match packet_id {
0xFE if self.stream.packet().len() < 0xFF_FF_FF => { 0xFE if self.stream.packet().len() < 0xFF_FF_FF => {
// OK or EOF packet // OK or EOF packet

View File

@ -8,8 +8,8 @@ use crate::mysql::protocol::{Capabilities, Decode, Status};
// https://mariadb.com/kb/en/eof_packet/ // https://mariadb.com/kb/en/eof_packet/
#[derive(Debug)] #[derive(Debug)]
pub struct EofPacket { pub struct EofPacket {
warnings: u16, pub warnings: u16,
status: Status, pub status: Status,
} }
impl Decode for EofPacket { impl Decode for EofPacket {

View File

@ -1,16 +1,11 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::str::{from_utf8, Utf8Error};
use std::sync::Arc; use std::sync::Arc;
use crate::decode::Decode;
use crate::error::UnexpectedNullError; use crate::error::UnexpectedNullError;
use crate::mysql::io::BufExt;
use crate::mysql::protocol; use crate::mysql::protocol;
use crate::mysql::MySql; use crate::mysql::MySql;
use crate::row::{ColumnIndex, Row}; use crate::row::{ColumnIndex, Row};
use crate::types::Type;
use byteorder::LittleEndian;
#[derive(Debug)] #[derive(Debug)]
pub enum MySqlValue<'c> { pub enum MySqlValue<'c> {
@ -49,7 +44,7 @@ impl<'c> Row<'c> for MySqlRow<'c> {
{ {
let index = index.resolve(self)?; let index = index.resolve(self)?;
Ok(self.row.get(index).map(|mut buf| { Ok(self.row.get(index).map(|buf| {
if self.binary { if self.binary {
MySqlValue::Binary(buf) MySqlValue::Binary(buf)
} else { } else {

View File

@ -169,13 +169,11 @@ impl MySqlStream {
Ok(()) Ok(())
} }
pub(crate) fn maybe_handle_eof(&mut self) -> crate::Result<bool> { pub(crate) fn maybe_handle_eof(&mut self) -> crate::Result<Option<EofPacket>> {
if !self.capabilities.contains(Capabilities::DEPRECATE_EOF) { if !self.capabilities.contains(Capabilities::DEPRECATE_EOF) {
let _eof = EofPacket::decode(self.packet())?; Ok(Some(EofPacket::decode(self.packet())?))
Ok(true)
} else { } else {
Ok(false) Ok(None)
} }
} }

View File

@ -1,47 +1,44 @@
use std::borrow::Cow;
use std::str::FromStr;
use crate::mysql::protocol::{Capabilities, SslRequest};
use crate::mysql::stream::MySqlStream; use crate::mysql::stream::MySqlStream;
use crate::url::Url; use crate::url::Url;
#[cfg_attr(not(feature = "tls"), allow(unused_variables))]
pub(super) async fn upgrade_if_needed(stream: &mut MySqlStream, url: &Url) -> crate::Result<()> { pub(super) async fn upgrade_if_needed(stream: &mut MySqlStream, url: &Url) -> crate::Result<()> {
#[cfg_attr(not(feature = "tls"), allow(unused_imports))]
use crate::mysql::protocol::Capabilities;
let ca_file = url.param("ssl-ca"); let ca_file = url.param("ssl-ca");
let ssl_mode = url.param("ssl-mode"); let ssl_mode = url.param("ssl-mode");
let supports_tls = stream.capabilities.contains(Capabilities::SSL);
// https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode // https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode
match ssl_mode.as_deref() { match ssl_mode.as_deref() {
Some("DISABLED") => {} Some("DISABLED") => {}
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
Some("PREFERRED") | None if !supports_tls => {} Some("PREFERRED") | None if !stream.capabilities.contains(Capabilities::SSL) => {}
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
Some("PREFERRED") => { Some("PREFERRED") => {
if let Err(error) = try_upgrade(stream, &url, None, true).await { if let Err(_error) = try_upgrade(stream, &url, None, true).await {
// TLS upgrade failed; fall back to a normal connection // TLS upgrade failed; fall back to a normal connection
} }
} }
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
None => { None => {
if let Err(error) = try_upgrade(stream, &url, ca_file.as_deref(), true).await { if let Err(_error) = try_upgrade(stream, &url, ca_file.as_deref(), true).await {
// TLS upgrade failed; fall back to a normal connection // TLS upgrade failed; fall back to a normal connection
} }
} }
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
Some(mode @ "REQUIRED") | Some(mode @ "VERIFY_CA") | Some(mode @ "VERIFY_IDENTITY") Some("REQUIRED") | Some("VERIFY_CA") | Some("VERIFY_IDENTITY")
if !supports_tls => if !stream.capabilities.contains(Capabilities::SSL) =>
{ {
return Err(tls_err!("server does not support TLS").into()); return Err(tls_err!("server does not support TLS").into());
} }
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
Some(mode @ "VERIFY_CA") | Some(mode @ "VERIFY_IDENTITY") if ca_file.is_none() => { Some("VERIFY_CA") | Some("VERIFY_IDENTITY") if ca_file.is_none() => {
return Err( return Err(
tls_err!("`ssl-mode` of {:?} requires `ssl-ca` to be set", ssl_mode).into(), tls_err!("`ssl-mode` of {:?} requires `ssl-ca` to be set", ssl_mode).into(),
); );
@ -93,6 +90,7 @@ async fn try_upgrade(
ca_file: Option<&str>, ca_file: Option<&str>,
accept_invalid_hostnames: bool, accept_invalid_hostnames: bool,
) -> crate::Result<()> { ) -> crate::Result<()> {
use crate::mysql::protocol::{SslRequest};
use crate::runtime::fs; use crate::runtime::fs;
use async_native_tls::{Certificate, TlsConnector}; use async_native_tls::{Certificate, TlsConnector};

View File

@ -2,7 +2,6 @@ use std::convert::TryInto;
use crate::decode::Decode; use crate::decode::Decode;
use crate::encode::Encode; use crate::encode::Encode;
use crate::error::UnexpectedNullError;
use crate::mysql::protocol::TypeId; use crate::mysql::protocol::TypeId;
use crate::mysql::types::MySqlTypeInfo; use crate::mysql::types::MySqlTypeInfo;
use crate::mysql::{MySql, MySqlValue}; use crate::mysql::{MySql, MySqlValue};

View File

@ -2,7 +2,6 @@ use byteorder::LittleEndian;
use crate::decode::Decode; use crate::decode::Decode;
use crate::encode::Encode; use crate::encode::Encode;
use crate::error::UnexpectedNullError;
use crate::mysql::io::{BufExt, BufMutExt}; use crate::mysql::io::{BufExt, BufMutExt};
use crate::mysql::protocol::TypeId; use crate::mysql::protocol::TypeId;
use crate::mysql::types::MySqlTypeInfo; use crate::mysql::types::MySqlTypeInfo;

View File

@ -4,7 +4,6 @@ use byteorder::{LittleEndian, ReadBytesExt};
use crate::decode::Decode; use crate::decode::Decode;
use crate::encode::Encode; use crate::encode::Encode;
use crate::error::UnexpectedNullError;
use crate::mysql::protocol::TypeId; use crate::mysql::protocol::TypeId;
use crate::mysql::types::MySqlTypeInfo; use crate::mysql::types::MySqlTypeInfo;
use crate::mysql::{MySql, MySqlValue}; use crate::mysql::{MySql, MySqlValue};

View File

@ -5,7 +5,6 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use crate::decode::Decode; use crate::decode::Decode;
use crate::encode::Encode; use crate::encode::Encode;
use crate::error::UnexpectedNullError;
use crate::mysql::protocol::TypeId; use crate::mysql::protocol::TypeId;
use crate::mysql::types::MySqlTypeInfo; use crate::mysql::types::MySqlTypeInfo;
use crate::mysql::{MySql, MySqlValue}; use crate::mysql::{MySql, MySqlValue};
@ -20,7 +19,7 @@ impl Type<MySql> for i8 {
impl Encode<MySql> for i8 { impl Encode<MySql> for i8 {
fn encode(&self, buf: &mut Vec<u8>) { fn encode(&self, buf: &mut Vec<u8>) {
buf.write_i8(*self); let _ = buf.write_i8(*self);
} }
} }
@ -45,7 +44,7 @@ impl Type<MySql> for i16 {
impl Encode<MySql> for i16 { impl Encode<MySql> for i16 {
fn encode(&self, buf: &mut Vec<u8>) { fn encode(&self, buf: &mut Vec<u8>) {
buf.write_i16::<LittleEndian>(*self); let _ = buf.write_i16::<LittleEndian>(*self);
} }
} }
@ -70,7 +69,7 @@ impl Type<MySql> for i32 {
impl Encode<MySql> for i32 { impl Encode<MySql> for i32 {
fn encode(&self, buf: &mut Vec<u8>) { fn encode(&self, buf: &mut Vec<u8>) {
buf.write_i32::<LittleEndian>(*self); let _ = buf.write_i32::<LittleEndian>(*self);
} }
} }
@ -95,7 +94,7 @@ impl Type<MySql> for i64 {
impl Encode<MySql> for i64 { impl Encode<MySql> for i64 {
fn encode(&self, buf: &mut Vec<u8>) { fn encode(&self, buf: &mut Vec<u8>) {
buf.write_i64::<LittleEndian>(*self); let _ = buf.write_i64::<LittleEndian>(*self);
} }
} }

View File

@ -4,7 +4,6 @@ use byteorder::LittleEndian;
use crate::decode::Decode; use crate::decode::Decode;
use crate::encode::Encode; use crate::encode::Encode;
use crate::error::UnexpectedNullError;
use crate::mysql::io::{BufExt, BufMutExt}; use crate::mysql::io::{BufExt, BufMutExt};
use crate::mysql::protocol::TypeId; use crate::mysql::protocol::TypeId;
use crate::mysql::types::MySqlTypeInfo; use crate::mysql::types::MySqlTypeInfo;

View File

@ -5,7 +5,6 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use crate::decode::Decode; use crate::decode::Decode;
use crate::encode::Encode; use crate::encode::Encode;
use crate::error::UnexpectedNullError;
use crate::mysql::protocol::TypeId; use crate::mysql::protocol::TypeId;
use crate::mysql::types::MySqlTypeInfo; use crate::mysql::types::MySqlTypeInfo;
use crate::mysql::{MySql, MySqlValue}; use crate::mysql::{MySql, MySqlValue};
@ -20,7 +19,7 @@ impl Type<MySql> for u8 {
impl Encode<MySql> for u8 { impl Encode<MySql> for u8 {
fn encode(&self, buf: &mut Vec<u8>) { fn encode(&self, buf: &mut Vec<u8>) {
buf.write_u8(*self); let _ = buf.write_u8(*self);
} }
} }
@ -45,7 +44,7 @@ impl Type<MySql> for u16 {
impl Encode<MySql> for u16 { impl Encode<MySql> for u16 {
fn encode(&self, buf: &mut Vec<u8>) { fn encode(&self, buf: &mut Vec<u8>) {
buf.write_u16::<LittleEndian>(*self); let _ = buf.write_u16::<LittleEndian>(*self);
} }
} }
@ -70,7 +69,7 @@ impl Type<MySql> for u32 {
impl Encode<MySql> for u32 { impl Encode<MySql> for u32 {
fn encode(&self, buf: &mut Vec<u8>) { fn encode(&self, buf: &mut Vec<u8>) {
buf.write_u32::<LittleEndian>(*self); let _ = buf.write_u32::<LittleEndian>(*self);
} }
} }
@ -95,7 +94,7 @@ impl Type<MySql> for u64 {
impl Encode<MySql> for u64 { impl Encode<MySql> for u64 {
fn encode(&self, buf: &mut Vec<u8>) { fn encode(&self, buf: &mut Vec<u8>) {
buf.write_u64::<LittleEndian>(*self); let _ = buf.write_u64::<LittleEndian>(*self);
} }
} }