Skip to content

Commit 837fbc0

Browse files
Merge pull request #513 from meven/fix-511
Fix clippy warnings, fix #511
2 parents 7a30226 + f5161da commit 837fbc0

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

src/group.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ fn read_toplevel_yaml(t: &GroupType, name: &str) -> io::Result<Group> {
4242
.join("team.yml");
4343
assert!(fs::metadata(&data_path)?.is_file());
4444
let data_string = fs::read_to_string(&data_path)?;
45-
let data: Group =
46-
serde_yaml::from_str(&data_string).expect(&format!("failed yaml parse for {} {}", t, name));
45+
let data: Group = serde_yaml::from_str(&data_string)
46+
.unwrap_or_else(|_| panic!("failed yaml parse for {} {}", t, name));
4747
Ok(data)
4848
}
4949

@@ -56,10 +56,8 @@ fn read_subs_yaml(t: &GroupType, group: &str, st: &GroupType, sub: &str) -> io::
5656
println!("trying to find {:?}", data_path);
5757
assert!(fs::metadata(&data_path)?.is_file());
5858
let data_string = fs::read_to_string(&data_path)?;
59-
let data: Group = serde_yaml::from_str(&data_string).expect(&format!(
60-
"failed yaml parse for {} {} {} {}",
61-
t, group, st, sub
62-
));
59+
let data: Group = serde_yaml::from_str(&data_string)
60+
.unwrap_or_else(|_| panic!("failed yaml parse for {} {} {} {}", t, group, st, sub));
6361
Ok(data)
6462
}
6563

@@ -69,7 +67,7 @@ pub fn get_toplevel_data(t: &GroupType) -> io::Result<Vec<Group>> {
6967
for group in groups_data {
7068
let group = group?;
7169
let data = read_toplevel_yaml(t, &get_name_from_path(group.path()))
72-
.expect(&format!("couldn't get toplevel group data for type {}", t));
70+
.unwrap_or_else(|_| panic!("couldn't get toplevel group data for type {}", t));
7371
groups.push(data);
7472
}
7573
Ok(groups)
@@ -97,13 +95,15 @@ pub fn get_subs_data(t: &GroupType, group: &str, st: &GroupType) -> io::Result<V
9795
let sub_data = fs::read_dir(data_path)?;
9896
for sub in sub_data {
9997
let sub = sub?;
100-
let data =
101-
read_subs_yaml(t, group, st, &get_name_from_path(sub.path())).expect(&format!(
102-
"couldn't get subs data for {} {} {}",
103-
t,
104-
group,
105-
get_name_from_path(sub.path())
106-
));
98+
let data = read_subs_yaml(t, group, st, &get_name_from_path(sub.path()))
99+
.unwrap_or_else(|_| {
100+
panic!(
101+
"couldn't get subs data for {} {} {}",
102+
t,
103+
group,
104+
get_name_from_path(sub.path())
105+
)
106+
});
107107
groups.push(data);
108108
}
109109
}

src/main.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn index() -> Template {
7676

7777
let context = Context {
7878
page: page.clone(),
79-
title: title,
79+
title,
8080
parent: "layout".to_string(),
8181
is_landing: true,
8282
rust_version: rust_version::rust_version()
@@ -96,7 +96,7 @@ fn category(category: Category) -> Template {
9696
let title = format!("Rust - {}", page).to_string();
9797
let context = Context {
9898
page: category.name().to_string(),
99-
title: title,
99+
title,
100100
parent: "layout".to_string(),
101101
is_landing: false,
102102
};
@@ -109,7 +109,7 @@ fn governance() -> Template {
109109
let title = format!("Rust - {}", page).to_string();
110110
let context = GroupContext {
111111
page: page.clone(),
112-
title: title,
112+
title,
113113
parent: "layout".to_string(),
114114
is_landing: false,
115115
data: load_governance_data(),
@@ -137,7 +137,7 @@ fn team(t: String, subject: String) -> Template {
137137
let t = get_type_from_string(&t).expect("couldnt figure out group type from path string");
138138
let context = GroupContext {
139139
page: page.clone(),
140-
title: title,
140+
title,
141141
parent: "layout".to_string(),
142142
is_landing: false,
143143
data: load_group_data(t, &subject),
@@ -163,12 +163,12 @@ fn load_group_data(t: GroupType, group: &str) -> HashMap<String, Vec<Group>> {
163163
);
164164
let subteams =
165165
group::get_subs_data(&t, group, &GroupType::Team).expect("couldn't get subteams data");
166-
if subteams.len() > 0 {
166+
if !subteams.is_empty() {
167167
map.insert("subteams".to_string(), subteams);
168168
}
169169
let subwgs = group::get_subs_data(&t, group, &GroupType::WorkingGroup)
170170
.expect("couldn't get subwgs data");
171-
if subwgs.len() > 0 {
171+
if !subwgs.is_empty() {
172172
map.insert("subwgs".to_string(), subwgs);
173173
}
174174
map
@@ -180,7 +180,7 @@ fn production() -> Template {
180180
let title = format!("Rust - {}", page).to_string();
181181
let context = UsersContext {
182182
page: page.clone(),
183-
title: title,
183+
title,
184184
parent: "layout".to_string(),
185185
is_landing: false,
186186
data: load_users_data(),
@@ -201,7 +201,7 @@ fn subject(category: Category, subject: String) -> Template {
201201
let title = format!("Rust - {}", page).to_string();
202202
let context = Context {
203203
page: subject,
204-
title: title,
204+
title,
205205
parent: "layout".to_string(),
206206
is_landing: false,
207207
};
@@ -214,7 +214,7 @@ fn not_found() -> Template {
214214
let title = format!("Rust - {}", page).to_string();
215215
let context = Context {
216216
page: "404".to_string(),
217-
title: title,
217+
title,
218218
parent: "layout".to_string(),
219219
is_landing: false,
220220
};
@@ -241,6 +241,7 @@ fn main() {
241241
.mount(
242242
"/",
243243
routes![index, category, governance, team, production, subject, files],
244-
).catch(catchers![not_found, catch_error])
244+
)
245+
.catch(catchers![not_found, catch_error])
245246
.launch();
246247
}

src/production.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn read_yaml() -> io::Result<Vec<User>> {
1717
assert!(fs::metadata(&data_path)?.is_file());
1818
let data_string = fs::read_to_string(&data_path)?;
1919
let data: Vec<User> = serde_yaml::from_str(&data_string)
20-
.expect(&format!("failed yaml parse for {}", data_path.display()));
20+
.unwrap_or_else(|_| panic!("failed yaml parse for {}", data_path.display()));
2121
Ok(data)
2222
}
2323

src/rust_version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ pub fn rust_version() -> Option<String> {
88
.ok()?;
99
let manifest = manifest.parse::<toml::Value>().ok()?;
1010
let rust_version = manifest["pkg"]["rust"]["version"].as_str()?.to_string();
11-
Some(rust_version[..rust_version.find(" ")?].to_string())
11+
Some(rust_version[..rust_version.find(' ')?].to_string())
1212
}

0 commit comments

Comments
 (0)