Refactor with the help of Clippy (#462)
We add clippy as our build — also rectifying the missing `plume-cli` build! In the next step we follow clippy's advise and fix some of the "simple" mistakes in our code, such as style or map usage. Finally, we refactor some hard bits that need extraction of new types, or refactoring of function call-types, especially those that thread thru macros, and, of course functions with ~15 parameters should probably be rethought.
This commit is contained in:
committed by
Baptiste Gelez
parent
570d7fe2d0
commit
732f514da7
@@ -171,6 +171,9 @@ impl User {
|
||||
.select(post_authors::post_id)
|
||||
.load(conn)?;
|
||||
for post_id in all_their_posts_ids {
|
||||
// disabling this lint, because otherwise we'd have to turn it on
|
||||
// the head, and make it even harder to follow!
|
||||
#[allow(clippy::op_ref)]
|
||||
let has_other_authors = post_authors::table
|
||||
.filter(post_authors::post_id.eq(post_id))
|
||||
.filter(post_authors::author_id.ne(self.id))
|
||||
@@ -489,7 +492,7 @@ impl User {
|
||||
Ok(json["items"]
|
||||
.as_array()
|
||||
.unwrap_or(&vec![])
|
||||
.into_iter()
|
||||
.iter()
|
||||
.filter_map(|j| serde_json::from_value(j.clone()).ok())
|
||||
.collect::<Vec<T>>())
|
||||
}
|
||||
@@ -512,7 +515,7 @@ impl User {
|
||||
Ok(json["items"]
|
||||
.as_array()
|
||||
.unwrap_or(&vec![])
|
||||
.into_iter()
|
||||
.iter()
|
||||
.filter_map(|j| serde_json::from_value(j.clone()).ok())
|
||||
.collect::<Vec<String>>())
|
||||
}
|
||||
@@ -746,7 +749,7 @@ impl User {
|
||||
pub fn avatar_url(&self, conn: &Connection) -> String {
|
||||
self.avatar_id.and_then(|id|
|
||||
Media::get(conn, id).and_then(|m| m.url(conn)).ok()
|
||||
).unwrap_or("/static/default-avatar.png".to_string())
|
||||
).unwrap_or_else(|| "/static/default-avatar.png".to_string())
|
||||
}
|
||||
|
||||
pub fn webfinger(&self, conn: &Connection) -> Result<Webfinger> {
|
||||
|
||||
Reference in New Issue
Block a user