Run cargo clippy on whole project (#322)

* Run cargo clippy on plume-common

Run clippy on plume-common and adjuste code accordingly

* Run cargo clippy on plume-model

Run clippy on plume-model and adjuste code accordingly

* Reduce need for allocation in plume-common

* Reduce need for allocation in plume-model

add a quick compilation failure if no database backend is enabled

* Run cargo clippy on plume-cli

* Run cargo clippy on plume
This commit is contained in:
fdb-hiroshima
2018-11-26 10:21:52 +01:00
committed by GitHub
parent 8a4702df92
commit 74c398d60c
36 changed files with 577 additions and 810 deletions
+17 -15
View File
@@ -30,7 +30,7 @@ pub struct NewMention {
impl Mention {
insert!(mentions, NewMention);
get!(mentions);
find_by!(mentions, find_by_ap_url, ap_url as String);
find_by!(mentions, find_by_ap_url, ap_url as &str);
list_by!(mentions, list_for_user, mentioned_id as i32);
list_by!(mentions, list_for_post, post_id as i32);
list_by!(mentions, list_for_comment, comment_id as i32);
@@ -54,12 +54,12 @@ impl Mention {
}
}
pub fn build_activity(conn: &Connection, ment: String) -> link::Mention {
let user = User::find_by_fqn(conn, ment.clone());
pub fn build_activity(conn: &Connection, ment: &str) -> link::Mention {
let user = User::find_by_fqn(conn, ment);
let mut mention = link::Mention::default();
mention
.link_props
.set_href_string(user.clone().map(|u| u.ap_url).unwrap_or(String::new()))
.set_href_string(user.clone().map(|u| u.ap_url).unwrap_or_default())
.expect("Mention::build_activity: href error");
mention
.link_props
@@ -73,13 +73,13 @@ impl Mention {
let mut mention = link::Mention::default();
mention
.link_props
.set_href_string(user.clone().map(|u| u.ap_url).unwrap_or(String::new()))
.set_href_string(user.clone().map(|u| u.ap_url).unwrap_or_default())
.expect("Mention::to_activity: href error");
mention
.link_props
.set_name_string(
user.map(|u| format!("@{}", u.get_fqn(conn)))
.unwrap_or(String::new()),
.unwrap_or_default(),
)
.expect("Mention::to_activity: mention error");
mention
@@ -87,23 +87,23 @@ impl Mention {
pub fn from_activity(
conn: &Connection,
ment: link::Mention,
ment: &link::Mention,
inside: i32,
in_post: bool,
notify: bool,
) -> Option<Self> {
let ap_url = ment.link_props.href_string().ok()?;
let mentioned = User::find_by_ap_url(conn, ap_url)?;
let mentioned = User::find_by_ap_url(conn, &ap_url)?;
if in_post {
Post::get(conn, inside.clone().into()).map(|post| {
Post::get(conn, inside).map(|post| {
let res = Mention::insert(
conn,
NewMention {
mentioned_id: mentioned.id,
post_id: Some(post.id),
comment_id: None,
ap_url: ment.link_props.href_string().unwrap_or(String::new()),
ap_url: ment.link_props.href_string().unwrap_or_default(),
},
);
if notify {
@@ -112,14 +112,14 @@ impl Mention {
res
})
} else {
Comment::get(conn, inside.into()).map(|comment| {
Comment::get(conn, inside).map(|comment| {
let res = Mention::insert(
conn,
NewMention {
mentioned_id: mentioned.id,
post_id: None,
comment_id: Some(comment.id),
ap_url: ment.link_props.href_string().unwrap_or(String::new()),
ap_url: ment.link_props.href_string().unwrap_or_default(),
},
);
if notify {
@@ -132,7 +132,9 @@ impl Mention {
pub fn delete(&self, conn: &Connection) {
//find related notifications and delete them
Notification::find(conn, notification_kind::MENTION, self.id).map(|n| n.delete(conn));
if let Some(n) = Notification::find(conn, notification_kind::MENTION, self.id) {
n.delete(conn)
}
diesel::delete(self)
.execute(conn)
.expect("Mention::delete: mention deletion error");
@@ -141,7 +143,7 @@ impl Mention {
impl Notify<Connection> for Mention {
fn notify(&self, conn: &Connection) {
self.get_mentioned(conn).map(|m| {
if let Some(m) = self.get_mentioned(conn) {
Notification::insert(
conn,
NewNotification {
@@ -150,6 +152,6 @@ impl Notify<Connection> for Mention {
user_id: m.id,
},
);
});
}
}
}