Skip to content

Commit 41ae4c0

Browse files
committed
cargo fmt again
1 parent 8d8305d commit 41ae4c0

25 files changed

+370
-440
lines changed

build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ fn main() {
1111
if env::var("PROFILE") == Ok("debug".into()) {
1212
let _ = dotenv();
1313
if let Ok(database_url) = env::var("TEST_DATABASE_URL") {
14-
let connection = PgConnection::establish(&database_url)
15-
.expect("Could not connect to TEST_DATABASE_URL");
14+
let connection = PgConnection::establish(&database_url).expect(
15+
"Could not connect to TEST_DATABASE_URL",
16+
);
1617
run_pending_migrations(&connection).expect("Error running migrations");
1718
}
1819
}

src/bin/populate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ fn main() {
2727
}
2828

2929
fn update(tx: &postgres::transaction::Transaction) -> postgres::Result<()> {
30-
let ids = env::args()
31-
.skip(1)
32-
.filter_map(|arg| arg.parse::<i32>().ok());
30+
let ids = env::args().skip(1).filter_map(
31+
|arg| arg.parse::<i32>().ok(),
32+
);
3333
for id in ids {
3434
let now = time::now_utc().to_timespec();
3535
let mut rng = StdRng::new().unwrap();

src/bin/update-downloads.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,9 @@ mod test {
174174
"SELECT * FROM crate_downloads
175175
WHERE crate_id = $1",
176176
).unwrap();
177-
let dl: i32 = stmt.query(&[&id])
178-
.unwrap()
179-
.iter()
180-
.next()
181-
.unwrap()
182-
.get("downloads");
177+
let dl: i32 = stmt.query(&[&id]).unwrap().iter().next().unwrap().get(
178+
"downloads",
179+
);
183180
assert_eq!(dl, expected as i32);
184181
}
185182

src/categories.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@ fn categories_from_toml(
5858
let mut result = vec![];
5959

6060
for (slug, details) in categories {
61-
let details = details
62-
.as_table()
63-
.chain_error(|| {
64-
internal(&format_args!("category {} was not a TOML table", slug))
65-
})?;
61+
let details = details.as_table().chain_error(|| {
62+
internal(&format_args!("category {} was not a TOML table", slug))
63+
})?;
6664

6765
let category = Category::from_parent(
6866
slug,
@@ -93,12 +91,12 @@ pub fn sync() -> CargoResult<()> {
9391
let tx = conn.transaction().unwrap();
9492

9593
let categories = include_str!("./categories.toml");
96-
let toml = toml::Parser::new(categories)
97-
.parse()
98-
.expect("Could not parse categories.toml");
94+
let toml = toml::Parser::new(categories).parse().expect(
95+
"Could not parse categories.toml",
96+
);
9997

100-
let categories = categories_from_toml(&toml, None)
101-
.expect("Could not convert categories from TOML");
98+
let categories =
99+
categories_from_toml(&toml, None).expect("Could not convert categories from TOML");
102100

103101
for category in &categories {
104102
tx.execute(

src/category.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ impl Category {
6363
WHERE category = $1",
6464
)?;
6565
let rows = stmt.query(&[&name])?;
66-
rows.iter()
67-
.next()
68-
.chain_error(|| NotFound)
69-
.map(|row| Model::from_row(&row))
66+
rows.iter().next().chain_error(|| NotFound).map(|row| {
67+
Model::from_row(&row)
68+
})
7069
}
7170

7271
pub fn find_by_slug(conn: &GenericConnection, slug: &str) -> CargoResult<Category> {
@@ -75,10 +74,9 @@ impl Category {
7574
WHERE slug = LOWER($1)",
7675
)?;
7776
let rows = stmt.query(&[&slug])?;
78-
rows.iter()
79-
.next()
80-
.chain_error(|| NotFound)
81-
.map(|row| Model::from_row(&row))
77+
rows.iter().next().chain_error(|| NotFound).map(|row| {
78+
Model::from_row(&row)
79+
})
8280
}
8381

8482
pub fn encodable(self) -> EncodableCategory {
@@ -429,8 +427,8 @@ mod tests {
429427

430428
fn pg_connection() -> PgConnection {
431429
let _ = dotenv();
432-
let database_url = env::var("TEST_DATABASE_URL")
433-
.expect("TEST_DATABASE_URL must be set to run tests");
430+
let database_url =
431+
env::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set to run tests");
434432
let conn = PgConnection::establish(&database_url).unwrap();
435433
// These tests deadlock if run concurrently
436434
conn.batch_execute("BEGIN; LOCK categories IN ACCESS EXCLUSIVE MODE")

src/db.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,9 @@ impl Transaction {
153153
&self,
154154
) -> CargoResult<&r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>> {
155155
if !self.slot.filled() {
156-
let conn = self.app
157-
.database
158-
.get()
159-
.map_err(|e| {
160-
internal(&format_args!("failed to get a database connection: {}", e))
161-
})?;
156+
let conn = self.app.database.get().map_err(|e| {
157+
internal(&format_args!("failed to get a database connection: {}", e))
158+
})?;
162159
self.slot.fill(Box::new(conn));
163160
}
164161
Ok(&**self.slot.borrow().unwrap())
@@ -205,16 +202,16 @@ impl Middleware for TransactionMiddleware {
205202
req: &mut Request,
206203
res: Result<Response, Box<Error + Send>>,
207204
) -> Result<Response, Box<Error + Send>> {
208-
let tx = req.mut_extensions()
209-
.pop::<Transaction>()
210-
.expect("Transaction not present in request");
205+
let tx = req.mut_extensions().pop::<Transaction>().expect(
206+
"Transaction not present in request",
207+
);
211208
if let Some(transaction) = tx.tx.into_inner() {
212209
if res.is_ok() && tx.commit.get() == Some(true) {
213210
transaction.set_commit();
214211
}
215-
transaction
216-
.finish()
217-
.map_err(|e| Box::new(e) as Box<Error + Send>)?;
212+
transaction.finish().map_err(
213+
|e| Box::new(e) as Box<Error + Send>,
214+
)?;
218215
}
219216
res
220217
}

src/dependency.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ impl Dependency {
125125

126126
impl ReverseDependency {
127127
pub fn encodable(self) -> EncodableDependency {
128-
self.dependency
129-
.encodable(&self.crate_name, Some(self.crate_downloads))
128+
self.dependency.encodable(
129+
&self.crate_name,
130+
Some(self.crate_downloads),
131+
)
130132
}
131133
}
132134

@@ -139,11 +141,11 @@ pub fn add_dependencies(
139141

140142
let git_and_new_dependencies = deps.iter()
141143
.map(|dep| {
142-
let krate = Crate::by_name(&dep.name)
143-
.first::<Crate>(&*conn)
144-
.map_err(|_| {
144+
let krate = Crate::by_name(&dep.name).first::<Crate>(&*conn).map_err(
145+
|_| {
145146
human(&format_args!("no known crate named `{}`", &*dep.name))
146-
})?;
147+
},
148+
)?;
147149
if dep.version_req == semver::VersionReq::parse("*").unwrap() {
148150
return Err(human(
149151
"wildcard (`*`) dependency constraints are not allowed \
@@ -189,17 +191,7 @@ pub fn add_dependencies(
189191
}
190192

191193
impl Queryable<dependencies::SqlType, Pg> for Dependency {
192-
type Row = (
193-
i32,
194-
i32,
195-
i32,
196-
String,
197-
bool,
198-
bool,
199-
Vec<String>,
200-
Option<String>,
201-
i32,
202-
);
194+
type Row = (i32, i32, i32, String, bool, bool, Vec<String>, Option<String>, i32);
203195

204196
fn build(row: Self::Row) -> Self {
205197
Dependency {

src/git.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ pub fn add_crate(app: &App, krate: &Crate) -> CargoResult<()> {
5656
fs::create_dir_all(dst.parent().unwrap())?;
5757
let mut prev = String::new();
5858
if fs::metadata(&dst).is_ok() {
59-
File::open(&dst)
60-
.and_then(|mut f| f.read_to_string(&mut prev))?;
59+
File::open(&dst).and_then(
60+
|mut f| f.read_to_string(&mut prev),
61+
)?;
6162
}
6263
let s = json::encode(krate).unwrap();
6364
let new = prev + &s;
@@ -79,12 +80,14 @@ pub fn yank(app: &App, krate: &str, version: &semver::Version, yanked: bool) ->
7980

8081
commit_and_push(&repo, || {
8182
let mut prev = String::new();
82-
File::open(&dst)
83-
.and_then(|mut f| f.read_to_string(&mut prev))?;
83+
File::open(&dst).and_then(
84+
|mut f| f.read_to_string(&mut prev),
85+
)?;
8486
let new = prev.lines()
8587
.map(|line| {
86-
let mut git_crate = json::decode::<Crate>(line)
87-
.map_err(|_| internal(&format_args!("couldn't decode: `{}`", line)))?;
88+
let mut git_crate = json::decode::<Crate>(line).map_err(|_| {
89+
internal(&format_args!("couldn't decode: `{}`", line))
90+
})?;
8891
if git_crate.name != krate || git_crate.vers != version.to_string() {
8992
return Ok(line.to_string());
9093
}
@@ -137,7 +140,14 @@ where
137140
let head = repo.head()?;
138141
let parent = repo.find_commit(head.target().unwrap())?;
139142
let sig = repo.signature()?;
140-
repo.commit(Some("HEAD"), &sig, &sig, &msg, &tree, &[&parent])?;
143+
repo.commit(
144+
Some("HEAD"),
145+
&sig,
146+
&sig,
147+
&msg,
148+
&tree,
149+
&[&parent],
150+
)?;
141151

142152
// git push
143153
let mut ref_status = None;

src/http.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ pub fn parse_github_response<T: Decodable>(mut resp: Easy, data: &[u8]) -> Cargo
6868
}
6969
}
7070

71-
let json = str::from_utf8(data)
72-
.ok()
73-
.chain_error(|| internal("github didn't send a utf8-response"))?;
71+
let json = str::from_utf8(data).ok().chain_error(|| {
72+
internal("github didn't send a utf8-response")
73+
})?;
7474

7575
json::decode(json).chain_error(|| internal("github didn't send a valid json response"))
7676
}

src/keyword.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ impl Keyword {
7979
return false;
8080
}
8181
name.chars().next().unwrap().is_alphanumeric() &&
82-
name.chars()
83-
.all(|c| c.is_alphanumeric() || c == '_' || c == '-') &&
84-
name.chars().all(|c| c.is_ascii())
82+
name.chars().all(
83+
|c| c.is_alphanumeric() || c == '_' || c == '-',
84+
) && name.chars().all(|c| c.is_ascii())
8585
}
8686

8787
pub fn encodable(self) -> EncodableKeyword {
@@ -102,8 +102,9 @@ impl Keyword {
102102
pub fn update_crate(conn: &PgConnection, krate: &Crate, keywords: &[&str]) -> QueryResult<()> {
103103
conn.transaction(|| {
104104
let keywords = Keyword::find_or_create_all(conn, keywords)?;
105-
diesel::delete(CrateKeyword::belonging_to(krate))
106-
.execute(conn)?;
105+
diesel::delete(CrateKeyword::belonging_to(krate)).execute(
106+
conn,
107+
)?;
107108
let crate_keywords = keywords
108109
.into_iter()
109110
.map(|kw| {

0 commit comments

Comments
 (0)