mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 14:34:19 +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
|
||||
/// from each query, in a stream.
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn fetch_many<'e, 'q: 'e, E: 'q>(
|
||||
self,
|
||||
query: E,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
//! Not intended to be used directly.
|
||||
#![recursion_limit = "512"]
|
||||
#![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.
|
||||
// <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);
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
async fn run<'c>(
|
||||
&'c mut self,
|
||||
query: &str,
|
||||
|
|
|
@ -21,8 +21,8 @@ impl MySqlBufExt for Bytes {
|
|||
fn get_uint_lenenc(&mut self) -> u64 {
|
||||
match self.get_u8() {
|
||||
0xfc => u64::from(self.get_u16_le()),
|
||||
0xfd => u64::from(self.get_uint_le(3)),
|
||||
0xfe => u64::from(self.get_u64_le()),
|
||||
0xfd => self.get_uint_le(3),
|
||||
0xfe => self.get_u64_le(),
|
||||
|
||||
v => u64::from(v),
|
||||
}
|
||||
|
|
|
@ -102,6 +102,12 @@ pub struct MySqlConnectOptions {
|
|||
pub(crate) ssl_ca: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Default for MySqlConnectOptions {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl MySqlConnectOptions {
|
||||
/// Creates a new, default set of options ready for configuration
|
||||
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 buf.get(0) == Some(&0x23) {
|
||||
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 {
|
||||
error_code,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![allow(clippy::all)]
|
||||
|
||||
use digest::Digest;
|
||||
use num_bigint::BigUint;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
|
|
@ -244,7 +244,7 @@ ORDER BY attnum
|
|||
|
||||
query_as_with::<_, (i32, Option<bool>), _>(&query, args)
|
||||
.fetch(self)
|
||||
.zip(stream::iter(columns.into_iter().enumerate()))
|
||||
.zip(stream::iter(columns.iter().enumerate()))
|
||||
.map(|(row, (field_idx, column))| -> Result<Column<_>, Error> {
|
||||
let (idx, not_null) = row?;
|
||||
|
||||
|
|
|
@ -74,13 +74,9 @@ impl PgConnection {
|
|||
loop {
|
||||
let message = self.stream.recv().await?;
|
||||
|
||||
match message.format {
|
||||
MessageFormat::ReadyForQuery => {
|
||||
self.handle_ready_for_query(message)?;
|
||||
break;
|
||||
}
|
||||
|
||||
_ => {}
|
||||
if let MessageFormat::ReadyForQuery = message.format {
|
||||
self.handle_ready_for_query(message)?;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ use rand::Rng;
|
|||
use sha2::digest::Digest;
|
||||
use sha2::Sha256;
|
||||
|
||||
const GS2_HEADER: &'static str = "n,,";
|
||||
const CHANNEL_ATTR: &'static str = "c";
|
||||
const USERNAME_ATTR: &'static str = "n";
|
||||
const CLIENT_PROOF_ATTR: &'static str = "p";
|
||||
const NONCE_ATTR: &'static str = "r";
|
||||
const GS2_HEADER: &str = "n,,";
|
||||
const CHANNEL_ATTR: &str = "c";
|
||||
const USERNAME_ATTR: &str = "n";
|
||||
const CLIENT_PROOF_ATTR: &str = "p";
|
||||
const NONCE_ATTR: &str = "r";
|
||||
|
||||
pub(crate) async fn authenticate(
|
||||
stream: &mut PgStream,
|
||||
|
|
|
@ -77,7 +77,7 @@ impl PgStream {
|
|||
|
||||
let contents = self.inner.read(size).await?;
|
||||
|
||||
return Ok(Message { format, contents });
|
||||
Ok(Message { format, contents })
|
||||
}
|
||||
|
||||
// Get the next message from the server
|
||||
|
|
|
@ -115,7 +115,7 @@ impl PgListener {
|
|||
|
||||
#[inline]
|
||||
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?;
|
||||
connection.stream.notifications = self.buffer_tx.take();
|
||||
|
||||
|
|
|
@ -179,12 +179,8 @@ impl Decode<'_> for AuthenticationSaslFinal {
|
|||
let key = item[0];
|
||||
let value = &item[2..];
|
||||
|
||||
match key {
|
||||
b'v' => {
|
||||
verifier = base64::decode(value).map_err(Error::protocol)?;
|
||||
}
|
||||
|
||||
_ => {}
|
||||
if let b'v' = key {
|
||||
verifier = base64::decode(value).map_err(Error::protocol)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -116,6 +116,12 @@ pub struct PgConnectOptions {
|
|||
pub(crate) ssl_root_cert: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Default for PgConnectOptions {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl PgConnectOptions {
|
||||
/// Creates a new, default set of options ready for configuration.
|
||||
///
|
||||
|
@ -289,16 +295,14 @@ fn default_host(port: u16) -> String {
|
|||
"/tmp", // Default
|
||||
];
|
||||
|
||||
'outer: loop {
|
||||
for candidate in &candidates {
|
||||
if Path::new(candidate).join(&socket).exists() {
|
||||
break 'outer candidate.to_string();
|
||||
}
|
||||
for candidate in &candidates {
|
||||
if Path::new(candidate).join(&socket).exists() {
|
||||
return candidate.to_string();
|
||||
}
|
||||
|
||||
// fallback to localhost if no socket was found
|
||||
break "localhost".to_owned();
|
||||
}
|
||||
|
||||
// fallback to localhost if no socket was found
|
||||
"localhost".to_owned()
|
||||
}
|
||||
|
||||
impl FromStr for PgConnectOptions {
|
||||
|
|
|
@ -603,7 +603,7 @@ impl TypeInfo for PgTypeInfo {}
|
|||
|
||||
impl PartialEq<PgCustomType> for PgCustomType {
|
||||
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() {
|
||||
PgValueFormat::Binary => value.as_bytes(),
|
||||
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 {
|
||||
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.
|
||||
#[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
|
||||
DB: Database,
|
||||
{
|
||||
|
|
|
@ -191,7 +191,7 @@ impl<'c> Executor<'c> for &'c mut SqliteConnection {
|
|||
columns.reserve(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 not_null = statement.column_not_null(i)?;
|
||||
|
||||
|
|
|
@ -12,6 +12,12 @@ pub struct SqliteConnectOptions {
|
|||
pub(crate) in_memory: bool,
|
||||
}
|
||||
|
||||
impl Default for SqliteConnectOptions {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl SqliteConnectOptions {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
|
Loading…
Reference in a new issue