Fix: clippy warning in rust 1.66.0

This commit is contained in:
Bo Zhang
2022-08-02 15:52:01 +08:00
committed by dlhxzb
parent d7b2060a5b
commit 60a6d672c5
18 changed files with 355 additions and 409 deletions

View File

@@ -1,6 +1,5 @@
use async_trait::async_trait;
use hbb_common::{log, ResultType};
use serde_json::value::Value;
use sqlx::{
sqlite::SqliteConnectOptions, ConnectOptions, Connection, Error as SqlxError, SqliteConnection,
};
@@ -8,7 +7,6 @@ use std::{ops::DerefMut, str::FromStr};
//use sqlx::postgres::PgPoolOptions;
//use sqlx::mysql::MySqlPoolOptions;
pub(crate) type MapValue = serde_json::map::Map<String, Value>;
type Pool = deadpool::managed::Pool<DbPool>;
pub struct DbPool {
@@ -54,7 +52,7 @@ impl Database {
std::fs::File::create(url).ok();
}
let n: usize = std::env::var("MAX_DATABASE_CONNECTIONS")
.unwrap_or("1".to_owned())
.unwrap_or_else(|_| "1".to_owned())
.parse()
.unwrap_or(1);
log::debug!("MAX_DATABASE_CONNECTIONS={}", n);
@@ -105,24 +103,6 @@ impl Database {
.await?)
}
#[inline]
pub async fn get_conn(&self) -> ResultType<deadpool::managed::Object<DbPool>> {
Ok(self.pool.get().await?)
}
pub async fn update_peer(&self, payload: MapValue, guid: &[u8]) -> ResultType<()> {
let mut conn = self.get_conn().await?;
let mut tx = conn.begin().await?;
if let Some(v) = payload.get("note") {
let v = get_str(v);
sqlx::query!("update peer set note = ? where guid = ?", v, guid)
.execute(&mut tx)
.await?;
}
tx.commit().await?;
Ok(())
}
pub async fn insert_peer(
&self,
id: &str,
@@ -199,17 +179,3 @@ mod tests {
hbb_common::futures::future::join_all(jobs).await;
}
}
pub(crate) fn get_str(v: &Value) -> Option<&str> {
match v {
Value::String(v) => {
let v = v.trim();
if v.is_empty() {
None
} else {
Some(v)
}
}
_ => None,
}
}