Skip to content

Commit 93fd8e5

Browse files
committed
try makes things cleaner
1 parent dd2ad05 commit 93fd8e5

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/version.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,19 @@ impl Version {
166166
}
167167

168168
pub fn authors(&self, conn: &GenericConnection) -> CargoResult<Vec<Author>> {
169-
let stmt = try!(conn.prepare("SELECT * FROM version_authors
170-
WHERE version_id = $1"));
171-
let rows = try!(stmt.query(&[&self.id]));
172-
let mut authors: CargoResult<Vec<Author>> = rows.into_iter().map(|row| {
169+
let stmt = conn.prepare("SELECT * FROM version_authors
170+
WHERE version_id = $1")?;
171+
let rows = stmt.query(&[&self.id])?;
172+
let mut authors = rows.into_iter().map(|row| {
173173
let user_id: Option<i32> = row.get("user_id");
174174
let name: String = row.get("name");
175175
Ok(match user_id {
176176
Some(id) => Author::User(User::find(conn, id)?),
177177
None => Author::Name(name),
178178
})
179-
}).collect();
180-
if let Ok(ref mut v) = authors {
181-
v.sort_by(|ref a, ref b| a.name().cmp(&b.name()));
182-
}
183-
authors
179+
}).collect::<CargoResult<Vec<Author>>>()?;
180+
authors.sort_by(|ref a, ref b| a.name().cmp(&b.name()));
181+
Ok(authors)
184182
}
185183

186184
pub fn add_author(&self,

0 commit comments

Comments
 (0)