Skip to content

Commit 22c5a6d

Browse files
yancoutofacebook-github-bot
authored andcommitted
sql: Use itertools to multiunzip instead of doing it manually
Summary: I always wanted this feature in Rust and just found out `itertools` has it :) So I'm using it here, where we were doing this manually because vanilla Rust only knows how to unzip 2-tuples. Doesn't change any behaviour, purely a refactor. Reviewed By: RajivTS Differential Revision: D40943893 fbshipit-source-id: bd4f63c89e07d69469152b8db78621f49219818f
1 parent 026a14a commit 22c5a6d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

shed/sql/common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ anyhow = "1.0.65"
1818
cloned = { version = "0.1.0", path = "../../cloned" }
1919
futures = { version = "0.3.22", features = ["async-await", "compat"] }
2020
futures_stats = { version = "0.1.0", path = "../../futures_stats" }
21+
itertools = "0.10.3"
2122
lazy_static = "1.4"
2223
mysql_async = "0.27.1"
2324
mysql_derive = { version = "0.1.0", path = "../derive" }

shed/sql/common/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ pub struct SqlShardedConnections {
125125
impl From<Vec1<SqlConnections>> for SqlShardedConnections {
126126
fn from(shard_connections: Vec1<SqlConnections>) -> Self {
127127
let (head, last) = shard_connections.split_off_last();
128-
let mut write_connections = Vec::with_capacity(head.len());
129-
let mut read_connections = Vec::with_capacity(head.len());
130-
let mut read_master_connections = Vec::with_capacity(head.len());
131-
for connections in head {
132-
write_connections.push(connections.write_connection);
133-
read_connections.push(connections.read_connection);
134-
read_master_connections.push(connections.read_master_connection);
135-
}
128+
let (write_connections, read_connections, read_master_connections) =
129+
itertools::multiunzip(head.into_iter().map(|conn| {
130+
(
131+
conn.write_connection,
132+
conn.read_connection,
133+
conn.read_master_connection,
134+
)
135+
}));
136136

137137
Self {
138138
read_connections: Vec1::from_vec_push(read_connections, last.read_connection),

0 commit comments

Comments
 (0)