Skip to content

Commit b20ba64

Browse files
committed
fix: fix some clippy warnings
1 parent 5394d5a commit b20ba64

File tree

3 files changed

+34
-49
lines changed

3 files changed

+34
-49
lines changed

src/types/models/dependency.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ use crate::types::api::ApiError;
88
use super::mod_gd_version::{GDVersionEnum, VerPlatform};
99

1010
#[derive(sqlx::FromRow, Clone)]
11-
pub struct Dependency {
12-
pub dependent_id: i32,
13-
pub dependency_id: String,
14-
pub compare: ModVersionCompare,
15-
pub importance: DependencyImportance,
16-
}
11+
pub struct Dependency {}
1712

1813
pub struct DependencyCreate {
1914
pub dependency_id: String,
@@ -172,7 +167,7 @@ impl Dependency {
172167
(!pre.is_empty()).then_some(pre)
173168
});
174169

175-
let q = sqlx::query_as::<Postgres, QueryResult>(
170+
let result: Vec<QueryResult> = sqlx::query_as(
176171
r#"
177172
WITH RECURSIVE dep_tree AS (
178173
SELECT * FROM (
@@ -301,15 +296,11 @@ impl Dependency {
301296
.bind(geode.map(|x| i32::try_from(x.major).unwrap_or_default()))
302297
.bind(geode.map(|x| i32::try_from(x.minor).unwrap_or_default()))
303298
.bind(geode.map(|x| i32::try_from(x.patch).unwrap_or_default()))
304-
.bind(geode_pre);
305-
306-
let result = match q.fetch_all(&mut *pool).await {
307-
Ok(d) => d,
308-
Err(e) => {
309-
log::error!("{}", e);
310-
return Err(ApiError::DbError);
311-
}
312-
};
299+
.bind(geode_pre)
300+
.fetch_all(&mut *pool)
301+
.await
302+
.inspect_err(|x| log::error!("Failed to fetch dependencies: {}", x))
303+
.or(Err(ApiError::DbError))?;
313304

314305
let mut ret: HashMap<i32, Vec<FetchedDependency>> = HashMap::new();
315306
for i in result {

src/types/models/incompatibility.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ pub struct IncompatibilityCreate {
2727
}
2828

2929
#[derive(sqlx::FromRow)]
30-
pub struct Incompatibility {
31-
pub mod_id: i32,
32-
pub incompatibility_id: String,
33-
pub compare: ModVersionCompare,
34-
pub importance: IncompatibilityImportance,
35-
}
30+
pub struct Incompatibility {}
3631

3732
#[derive(Debug, Serialize, Clone)]
3833
pub struct Replacement {
@@ -110,25 +105,23 @@ impl Incompatibility {
110105
Ok(())
111106
}
112107

113-
pub async fn clear_for_mod_version(
114-
id: i32,
115-
pool: &mut PgConnection
116-
) -> Result<(), ApiError> {
108+
pub async fn clear_for_mod_version(id: i32, pool: &mut PgConnection) -> Result<(), ApiError> {
117109
sqlx::query!(
118110
"DELETE FROM incompatibilities
119111
WHERE mod_id = $1",
120112
id
121113
)
122-
.execute(&mut *pool)
123-
.await
124-
.map(|_| ())
125-
.map_err(|err| {
126-
log::error!(
127-
"Failed to remove incompatibilities for mod version {}: {}",
128-
id, err
129-
);
130-
ApiError::DbError
131-
})
114+
.execute(&mut *pool)
115+
.await
116+
.map(|_| ())
117+
.map_err(|err| {
118+
log::error!(
119+
"Failed to remove incompatibilities for mod version {}: {}",
120+
id,
121+
err
122+
);
123+
ApiError::DbError
124+
})
132125
}
133126

134127
pub async fn get_for_mod_version(
@@ -162,10 +155,14 @@ impl Incompatibility {
162155
geode: Option<&semver::Version>,
163156
pool: &mut PgConnection,
164157
) -> Result<HashMap<i32, Vec<FetchedIncompatibility>>, ApiError> {
165-
let geode_pre = geode.map(|x| {
166-
let pre = x.pre.to_string();
167-
(!pre.is_empty()).then(|| pre)
168-
}).flatten();
158+
let geode_pre = geode
159+
.and_then(|x| {
160+
if x.pre.is_empty() {
161+
None
162+
} else {
163+
Some(x.pre.to_string())
164+
}
165+
});
169166

170167
let q = sqlx::query_as::<Postgres, FetchedIncompatibility>(
171168
r#"SELECT icp.compare,
@@ -227,8 +224,11 @@ impl Incompatibility {
227224
pool: &mut PgConnection,
228225
) -> Result<HashMap<String, Replacement>, ApiError> {
229226
let mut ret: HashMap<String, Replacement> = HashMap::new();
230-
let pre = geode.pre.to_string();
231-
let pre = (!pre.is_empty()).then(|| pre);
227+
let pre = if geode.pre.is_empty() {
228+
None
229+
} else {
230+
Some(geode.pre.to_string())
231+
};
232232
let r = match sqlx::query!(
233233
r#"
234234
SELECT

src/types/models/mod_version_status.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ pub enum ModVersionStatusEnum {
1313
Unlisted,
1414
}
1515

16-
pub struct ModVersionStatus {
17-
pub id: i32,
18-
pub mod_version_id: i32,
19-
pub status: ModVersionStatusEnum,
20-
pub info: Option<String>,
21-
pub admin_id: i32,
22-
}
16+
pub struct ModVersionStatus {}
2317

2418
impl ModVersionStatus {
2519
pub async fn create_for_mod_version(

0 commit comments

Comments
 (0)