mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-14 00:07:05 +00:00
style(core): apply more clippy suggestions
This commit is contained in:
parent
35bf560481
commit
3fcd4cd80e
22 changed files with 52 additions and 41 deletions
|
@ -75,7 +75,6 @@ pub trait Executor<'c>: Send + Debug + Sized {
|
||||||
|
|
||||||
/// Execute multiple queries and return the generated results as a stream
|
/// Execute multiple queries and return the generated results as a stream
|
||||||
/// from each query, in a stream.
|
/// from each query, in a stream.
|
||||||
#[allow(clippy::type_complexity)]
|
|
||||||
fn fetch_many<'e, 'q: 'e, E: 'q>(
|
fn fetch_many<'e, 'q: 'e, E: 'q>(
|
||||||
self,
|
self,
|
||||||
query: E,
|
query: E,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//! Not intended to be used directly.
|
//! Not intended to be used directly.
|
||||||
#![recursion_limit = "512"]
|
#![recursion_limit = "512"]
|
||||||
#![warn(future_incompatible, rust_2018_idioms)]
|
#![warn(future_incompatible, rust_2018_idioms)]
|
||||||
|
#![allow(clippy::needless_doctest_main, clippy::type_complexity)]
|
||||||
//
|
//
|
||||||
// Allows an API be documented as only available in some specific platforms.
|
// Allows an API be documented as only available in some specific platforms.
|
||||||
// <https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html>
|
// <https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html>
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl<'q> Arguments<'q> for MySqlArguments {
|
||||||
self.null_bitmap.resize((index / 8) + 1, 0);
|
self.null_bitmap.resize((index / 8) + 1, 0);
|
||||||
|
|
||||||
if let IsNull::Yes = value.encode(self) {
|
if let IsNull::Yes = value.encode(self) {
|
||||||
self.null_bitmap[index / 8] |= (1 << index % 8) as u8;
|
self.null_bitmap[index / 8] |= (1 << (index % 8)) as u8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,7 @@ impl MySqlConnection {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::needless_lifetimes)]
|
||||||
async fn run<'c>(
|
async fn run<'c>(
|
||||||
&'c mut self,
|
&'c mut self,
|
||||||
query: &str,
|
query: &str,
|
||||||
|
|
|
@ -21,8 +21,8 @@ impl MySqlBufExt for Bytes {
|
||||||
fn get_uint_lenenc(&mut self) -> u64 {
|
fn get_uint_lenenc(&mut self) -> u64 {
|
||||||
match self.get_u8() {
|
match self.get_u8() {
|
||||||
0xfc => u64::from(self.get_u16_le()),
|
0xfc => u64::from(self.get_u16_le()),
|
||||||
0xfd => u64::from(self.get_uint_le(3)),
|
0xfd => self.get_uint_le(3),
|
||||||
0xfe => u64::from(self.get_u64_le()),
|
0xfe => self.get_u64_le(),
|
||||||
|
|
||||||
v => u64::from(v),
|
v => u64::from(v),
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,12 @@ pub struct MySqlConnectOptions {
|
||||||
pub(crate) ssl_ca: Option<PathBuf>,
|
pub(crate) ssl_ca: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for MySqlConnectOptions {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MySqlConnectOptions {
|
impl MySqlConnectOptions {
|
||||||
/// Creates a new, default set of options ready for configuration
|
/// Creates a new, default set of options ready for configuration
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
|
|
@ -32,11 +32,11 @@ impl Decode<'_, Capabilities> for ErrPacket {
|
||||||
// If the next byte is '#' then we have a SQL STATE
|
// If the next byte is '#' then we have a SQL STATE
|
||||||
if buf.get(0) == Some(&0x23) {
|
if buf.get(0) == Some(&0x23) {
|
||||||
buf.advance(1);
|
buf.advance(1);
|
||||||
sql_state = Some(buf.get_str(5)?.to_owned());
|
sql_state = Some(buf.get_str(5)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let error_message = buf.get_str(buf.len())?.to_owned();
|
let error_message = buf.get_str(buf.len())?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
error_code,
|
error_code,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![allow(clippy::all)]
|
||||||
|
|
||||||
use digest::Digest;
|
use digest::Digest;
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
|
|
@ -244,7 +244,7 @@ ORDER BY attnum
|
||||||
|
|
||||||
query_as_with::<_, (i32, Option<bool>), _>(&query, args)
|
query_as_with::<_, (i32, Option<bool>), _>(&query, args)
|
||||||
.fetch(self)
|
.fetch(self)
|
||||||
.zip(stream::iter(columns.into_iter().enumerate()))
|
.zip(stream::iter(columns.iter().enumerate()))
|
||||||
.map(|(row, (field_idx, column))| -> Result<Column<_>, Error> {
|
.map(|(row, (field_idx, column))| -> Result<Column<_>, Error> {
|
||||||
let (idx, not_null) = row?;
|
let (idx, not_null) = row?;
|
||||||
|
|
||||||
|
|
|
@ -74,14 +74,10 @@ impl PgConnection {
|
||||||
loop {
|
loop {
|
||||||
let message = self.stream.recv().await?;
|
let message = self.stream.recv().await?;
|
||||||
|
|
||||||
match message.format {
|
if let MessageFormat::ReadyForQuery = message.format {
|
||||||
MessageFormat::ReadyForQuery => {
|
|
||||||
self.handle_ready_for_query(message)?;
|
self.handle_ready_for_query(message)?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,11 @@ use rand::Rng;
|
||||||
use sha2::digest::Digest;
|
use sha2::digest::Digest;
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
|
|
||||||
const GS2_HEADER: &'static str = "n,,";
|
const GS2_HEADER: &str = "n,,";
|
||||||
const CHANNEL_ATTR: &'static str = "c";
|
const CHANNEL_ATTR: &str = "c";
|
||||||
const USERNAME_ATTR: &'static str = "n";
|
const USERNAME_ATTR: &str = "n";
|
||||||
const CLIENT_PROOF_ATTR: &'static str = "p";
|
const CLIENT_PROOF_ATTR: &str = "p";
|
||||||
const NONCE_ATTR: &'static str = "r";
|
const NONCE_ATTR: &str = "r";
|
||||||
|
|
||||||
pub(crate) async fn authenticate(
|
pub(crate) async fn authenticate(
|
||||||
stream: &mut PgStream,
|
stream: &mut PgStream,
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl PgStream {
|
||||||
|
|
||||||
let contents = self.inner.read(size).await?;
|
let contents = self.inner.read(size).await?;
|
||||||
|
|
||||||
return Ok(Message { format, contents });
|
Ok(Message { format, contents })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the next message from the server
|
// Get the next message from the server
|
||||||
|
|
|
@ -115,7 +115,7 @@ impl PgListener {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn connect_if_needed(&mut self) -> Result<(), Error> {
|
async fn connect_if_needed(&mut self) -> Result<(), Error> {
|
||||||
if let None = self.connection {
|
if self.connection.is_none() {
|
||||||
let mut connection = self.pool.acquire().await?;
|
let mut connection = self.pool.acquire().await?;
|
||||||
connection.stream.notifications = self.buffer_tx.take();
|
connection.stream.notifications = self.buffer_tx.take();
|
||||||
|
|
||||||
|
|
|
@ -179,13 +179,9 @@ impl Decode<'_> for AuthenticationSaslFinal {
|
||||||
let key = item[0];
|
let key = item[0];
|
||||||
let value = &item[2..];
|
let value = &item[2..];
|
||||||
|
|
||||||
match key {
|
if let b'v' = key {
|
||||||
b'v' => {
|
|
||||||
verifier = base64::decode(value).map_err(Error::protocol)?;
|
verifier = base64::decode(value).map_err(Error::protocol)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self { verifier })
|
Ok(Self { verifier })
|
||||||
|
|
|
@ -116,6 +116,12 @@ pub struct PgConnectOptions {
|
||||||
pub(crate) ssl_root_cert: Option<PathBuf>,
|
pub(crate) ssl_root_cert: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for PgConnectOptions {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PgConnectOptions {
|
impl PgConnectOptions {
|
||||||
/// Creates a new, default set of options ready for configuration.
|
/// Creates a new, default set of options ready for configuration.
|
||||||
///
|
///
|
||||||
|
@ -289,16 +295,14 @@ fn default_host(port: u16) -> String {
|
||||||
"/tmp", // Default
|
"/tmp", // Default
|
||||||
];
|
];
|
||||||
|
|
||||||
'outer: loop {
|
|
||||||
for candidate in &candidates {
|
for candidate in &candidates {
|
||||||
if Path::new(candidate).join(&socket).exists() {
|
if Path::new(candidate).join(&socket).exists() {
|
||||||
break 'outer candidate.to_string();
|
return candidate.to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback to localhost if no socket was found
|
// fallback to localhost if no socket was found
|
||||||
break "localhost".to_owned();
|
"localhost".to_owned()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for PgConnectOptions {
|
impl FromStr for PgConnectOptions {
|
||||||
|
|
|
@ -603,7 +603,7 @@ impl TypeInfo for PgTypeInfo {}
|
||||||
|
|
||||||
impl PartialEq<PgCustomType> for PgCustomType {
|
impl PartialEq<PgCustomType> for PgCustomType {
|
||||||
fn eq(&self, other: &PgCustomType) -> bool {
|
fn eq(&self, other: &PgCustomType) -> bool {
|
||||||
return other.oid == self.oid;
|
other.oid == self.oid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl<'r> Decode<'r, Postgres> for &'r [u8] {
|
||||||
match value.format() {
|
match value.format() {
|
||||||
PgValueFormat::Binary => value.as_bytes(),
|
PgValueFormat::Binary => value.as_bytes(),
|
||||||
PgValueFormat::Text => {
|
PgValueFormat::Text => {
|
||||||
return Err("unsupported decode to `&[u8]` of BYTEA in a simple query; use a prepared query or decode to `Vec<u8>`".into());
|
Err("unsupported decode to `&[u8]` of BYTEA in a simple query; use a prepared query or decode to `Vec<u8>`".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,6 @@ impl Decode<'_, Postgres> for IpNetwork {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Err(format!("invalid data received when expecting an INET").into());
|
Err("invalid data received when expecting an INET".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl Encode<'_, Postgres> for &'_ str {
|
||||||
|
|
||||||
impl Encode<'_, Postgres> for String {
|
impl Encode<'_, Postgres> for String {
|
||||||
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
|
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
|
||||||
<&str as Encode<Postgres>>::encode(&mut &**self, buf)
|
<&str as Encode<Postgres>>::encode(&**self, buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -302,7 +302,7 @@ where
|
||||||
|
|
||||||
/// Make a SQL query.
|
/// Make a SQL query.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn query<'q, DB>(sql: &'q str) -> Query<'q, DB, <DB as HasArguments<'q>>::Arguments>
|
pub fn query<DB>(sql: &str) -> Query<'_, DB, <DB as HasArguments<'_>>::Arguments>
|
||||||
where
|
where
|
||||||
DB: Database,
|
DB: Database,
|
||||||
{
|
{
|
||||||
|
|
|
@ -191,7 +191,7 @@ impl<'c> Executor<'c> for &'c mut SqliteConnection {
|
||||||
columns.reserve(num_columns);
|
columns.reserve(num_columns);
|
||||||
|
|
||||||
for i in 0..num_columns {
|
for i in 0..num_columns {
|
||||||
let name = statement.column_name(i).to_owned().into();
|
let name = statement.column_name(i).to_owned();
|
||||||
let type_info = statement.column_decltype(i);
|
let type_info = statement.column_decltype(i);
|
||||||
let not_null = statement.column_not_null(i)?;
|
let not_null = statement.column_not_null(i)?;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,12 @@ pub struct SqliteConnectOptions {
|
||||||
pub(crate) in_memory: bool,
|
pub(crate) in_memory: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for SqliteConnectOptions {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SqliteConnectOptions {
|
impl SqliteConnectOptions {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
Loading…
Reference in a new issue