Skip to content

Commit

Permalink
Clippy.
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGariepy committed Feb 8, 2023
1 parent 7c7d5ab commit 493b75b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 54 deletions.
26 changes: 8 additions & 18 deletions bench/usage/cornucopia_benches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) {
let mut stmt = insert_user();
b.iter(|| {
block_on(async {
let mut tx = client.transaction().await.unwrap();
let tx = client.transaction().await.unwrap();
for x in 0..size {
stmt.bind(
&mut tx,
&format!("User {}", x).as_str(),
&Some("hair_color"),
)
.await
.unwrap();
stmt.bind(&tx, &format!("User {x}").as_str(), &Some("hair_color"))
.await
.unwrap();
}
tx.commit().await.unwrap();
})
Expand Down Expand Up @@ -105,8 +101,7 @@ pub fn loading_associations_sequentially(b: &mut Bencher, client: &Client) {
}

users
.into_iter()
.map(|(_, users_with_post_and_comment)| users_with_post_and_comment)
.into_values()
.collect::<Vec<(User, Vec<(Post, Vec<Comment>)>)>>()
})
})
Expand Down Expand Up @@ -156,12 +151,8 @@ pub mod sync {
b.iter(|| {
let mut tx = client.transaction().unwrap();
for x in 0..size {
stmt.bind(
&mut tx,
&format!("User {}", x).as_str(),
&Some("hair_color"),
)
.unwrap();
stmt.bind(&mut tx, &format!("User {x}").as_str(), &Some("hair_color"))
.unwrap();
}
tx.commit().unwrap();
})
Expand Down Expand Up @@ -205,8 +196,7 @@ pub mod sync {
}

users
.into_iter()
.map(|(_, users_with_post_and_comment)| users_with_post_and_comment)
.into_values()
.collect::<Vec<(User, Vec<(Post, Vec<Comment>)>)>>()
})
}
Expand Down
4 changes: 2 additions & 2 deletions bench/usage/diesel_benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn insert_users<F: Fn(usize) -> Option<&'static str>, const N: usize>(
let mut data = Box::new([DUMMY_USER; N]);

for (idx, user) in data.iter_mut().enumerate() {
*user = NewUser::new(&format!("User {}", idx), hair_color_init(idx));
*user = NewUser::new(&format!("User {idx}"), hair_color_init(idx));
}

insert_into(users::table)
Expand All @@ -125,7 +125,7 @@ fn insert_users<F: Fn(usize) -> Option<&'static str>, const N: usize>(
let mut data = [DUMMY_USER; N];

for (idx, user) in data.iter_mut().enumerate() {
*user = NewUser::new(&format!("User {}", idx), hair_color_init(idx));
*user = NewUser::new(&format!("User {idx}"), hair_color_init(idx));
}

insert_into(users::table)
Expand Down
6 changes: 3 additions & 3 deletions bench/usage/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn prepare_client(
2 * x + 2
)
.unwrap();
params.push((format!("User {}", x), hair_color_init(x)));
params.push((format!("User {x}"), hair_color_init(x)));
}

let params = params
Expand All @@ -63,7 +63,7 @@ fn prepare_full(client: &mut Client) {
let data = user_ids
.iter()
.flat_map(|user_id| {
(0..10).map(move |i| (format!("Post {} by user {}", i, user_id), user_id, None))
(0..10).map(move |i| (format!("Post {i} by user {user_id}"), user_id, None))
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -100,7 +100,7 @@ fn prepare_full(client: &mut Client) {
let data = all_posts
.iter()
.flat_map(|post_id| {
(0..10).map(move |i| (format!("Comment {} on post {}", i, post_id), post_id))
(0..10).map(move |i| (format!("Comment {i} on post {post_id}"), post_id))
})
.collect::<Vec<_>>();

Expand Down
21 changes: 8 additions & 13 deletions bench/usage/postgres_benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,12 @@ pub fn bench_medium_complex_query(b: &mut Bencher, client: &mut Client) {
name: row.get(1),
hair_color: row.get(2),
};
let post = if let Some(id) = row.get(3) {
Some(Post {
id,
user_id: row.get(4),
title: row.get(5),
body: row.get(6),
})
} else {
None
};
let post = row.get::<usize, Option<i32>>(3).map(|id| Post {
id,
user_id: row.get(4),
title: row.get(5),
body: row.get(6),
});
Ok((user, post))
})
.collect::<Vec<_>>()
Expand All @@ -97,7 +93,7 @@ pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) {
2 * x + 2
)
.unwrap();
params.push((format!("User {}", x), Some("hair_color")));
params.push((format!("User {x}"), Some("hair_color")));
}

let params = params
Expand Down Expand Up @@ -206,8 +202,7 @@ pub fn loading_associations_sequentially(b: &mut Bencher, client: &mut Client) {
}

users
.into_iter()
.map(|(_, users_with_post_and_comment)| users_with_post_and_comment)
.into_values()
.collect::<Vec<(User, Vec<(Post, Vec<Comment>)>)>>()
})
}
21 changes: 8 additions & 13 deletions bench/usage/tokio_postgres_benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,12 @@ pub fn bench_medium_complex_query(b: &mut Bencher, client: &mut Client) {
name: row.get(1),
hair_color: row.get(2),
},
if let Some(id) = row.get(3) {
Some(Post {
id,
user_id: row.get(4),
title: row.get(5),
body: row.get(6),
})
} else {
None
},
row.get::<usize, Option<i32>>(3).map(|id| Post {
id,
user_id: row.get(4),
title: row.get(5),
body: row.get(6),
}),
)
})
})
Expand All @@ -116,7 +112,7 @@ pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) {
2 * x + 2
)
.unwrap();
params.push((format!("User {}", x), Some("hair_color")));
params.push((format!("User {x}"), Some("hair_color")));
}

let params = params
Expand Down Expand Up @@ -236,8 +232,7 @@ pub fn loading_associations_sequentially(b: &mut Bencher, client: &mut Client) {
}

users
.into_iter()
.map(|(_, users_with_post_and_comment)| users_with_post_and_comment)
.into_values()
.collect::<Vec<(User, Vec<(Post, Vec<Comment>)>)>>()
});
})
Expand Down
10 changes: 5 additions & 5 deletions cornucopia/src/type_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl CornucopiaType {
} => {
if !is_copy && !is_params {
let path = custom_ty_path(pg_ty.schema(), struct_name, ctx);
format!("{}Params<'a>", path)
format!("{path}Params<'a>")
} else {
self.brw_ty(is_inner_nullable, true, ctx)
}
Expand Down Expand Up @@ -293,7 +293,7 @@ impl CornucopiaType {
if *is_copy {
path
} else {
format!("{}Borrowed<{lifetime}>", path)
format!("{path}Borrowed<{lifetime}>")
}
}
}
Expand All @@ -302,13 +302,13 @@ impl CornucopiaType {

pub fn custom_ty_path(schema: &str, struct_name: &str, ctx: &GenCtx) -> String {
if ctx.depth == 0 {
format!("{}::{}", schema, struct_name)
format!("{schema}::{struct_name}")
} else if ctx.depth == 1 {
format!("super::{}::{}", schema, struct_name)
format!("super::{schema}::{struct_name}")
} else {
ctx.path(
ctx.depth,
format_args!("types::{}::{}", schema, struct_name),
format_args!("types::{schema}::{struct_name}"),
)
}
}
Expand Down

0 comments on commit 493b75b

Please sign in to comment.