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:
@@ -74,7 +74,7 @@ impl Instance {
|
||||
|
||||
insert!(instances, NewInstance);
|
||||
get!(instances);
|
||||
find_by!(instances, find_by_domain, public_domain as String);
|
||||
find_by!(instances, find_by_domain, public_domain as &str);
|
||||
|
||||
pub fn toggle_block(&self, conn: &Connection) {
|
||||
diesel::update(self)
|
||||
@@ -84,13 +84,13 @@ impl Instance {
|
||||
}
|
||||
|
||||
/// id: AP object id
|
||||
pub fn is_blocked(conn: &Connection, id: String) -> bool {
|
||||
pub fn is_blocked(conn: &Connection, id: &str) -> bool {
|
||||
for block in instances::table
|
||||
.filter(instances::blocked.eq(true))
|
||||
.get_results::<Instance>(conn)
|
||||
.expect("Instance::is_blocked: loading error")
|
||||
{
|
||||
if id.starts_with(format!("https://{}/", block.public_domain).as_str()) {
|
||||
if id.starts_with(&format!("https://{}/", block.public_domain)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -99,12 +99,12 @@ impl Instance {
|
||||
}
|
||||
|
||||
pub fn has_admin(&self, conn: &Connection) -> bool {
|
||||
users::table
|
||||
!users::table
|
||||
.filter(users::instance_id.eq(self.id))
|
||||
.filter(users::is_admin.eq(true))
|
||||
.load::<User>(conn)
|
||||
.expect("Instance::has_admin: loading error")
|
||||
.len() > 0
|
||||
.is_empty()
|
||||
}
|
||||
|
||||
pub fn main_admin(&self, conn: &Connection) -> User {
|
||||
@@ -118,11 +118,11 @@ impl Instance {
|
||||
|
||||
pub fn compute_box(
|
||||
&self,
|
||||
prefix: &'static str,
|
||||
name: String,
|
||||
box_name: &'static str,
|
||||
prefix: &str,
|
||||
name: &str,
|
||||
box_name: &str,
|
||||
) -> String {
|
||||
ap_url(format!(
|
||||
ap_url(&format!(
|
||||
"{instance}/{prefix}/{name}/{box_name}",
|
||||
instance = self.public_domain,
|
||||
prefix = prefix,
|
||||
@@ -219,7 +219,7 @@ pub(crate) mod tests {
|
||||
.map(|inst| {
|
||||
(
|
||||
inst.clone(),
|
||||
Instance::find_by_domain(conn, inst.public_domain.clone())
|
||||
Instance::find_by_domain(conn, &inst.public_domain)
|
||||
.unwrap_or_else(|| Instance::insert(conn, inst)),
|
||||
)
|
||||
})
|
||||
@@ -332,12 +332,12 @@ pub(crate) mod tests {
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Instance::is_blocked(conn, format!("https://{}/something", inst.public_domain)),
|
||||
Instance::is_blocked(conn, &format!("https://{}/something", inst.public_domain)),
|
||||
inst.blocked
|
||||
);
|
||||
assert_eq!(
|
||||
Instance::is_blocked(conn, format!("https://{}a/something", inst.public_domain)),
|
||||
Instance::find_by_domain(conn, format!("{}a", inst.public_domain))
|
||||
Instance::is_blocked(conn, &format!("https://{}a/something", inst.public_domain)),
|
||||
Instance::find_by_domain(conn, &format!("{}a", inst.public_domain))
|
||||
.map(|inst| inst.blocked)
|
||||
.unwrap_or(false)
|
||||
);
|
||||
@@ -346,12 +346,12 @@ pub(crate) mod tests {
|
||||
let inst = Instance::get(conn, inst.id).unwrap();
|
||||
assert_eq!(inst.blocked, blocked);
|
||||
assert_eq!(
|
||||
Instance::is_blocked(conn, format!("https://{}/something", inst.public_domain)),
|
||||
Instance::is_blocked(conn, &format!("https://{}/something", inst.public_domain)),
|
||||
inst.blocked
|
||||
);
|
||||
assert_eq!(
|
||||
Instance::is_blocked(conn, format!("https://{}a/something", inst.public_domain)),
|
||||
Instance::find_by_domain(conn, format!("{}a", inst.public_domain))
|
||||
Instance::is_blocked(conn, &format!("https://{}a/something", inst.public_domain)),
|
||||
Instance::find_by_domain(conn, &format!("{}a", inst.public_domain))
|
||||
.map(|inst| inst.blocked)
|
||||
.unwrap_or(false)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user