Simplify match nesting in theme with if let
This commit is contained in:
parent
37b68c41f7
commit
c113c2eb31
|
@ -60,58 +60,33 @@ impl Theme {
|
|||
// Check for individual files if they exist
|
||||
|
||||
// index.hbs
|
||||
match File::open(&src.join("index.hbs")) {
|
||||
Ok(mut f) => {
|
||||
if let Ok(mut f) = File::open(&src.join("index.hbs")) {
|
||||
theme.index.clear(); // Reset the value, because read_to_string appends...
|
||||
match f.read_to_end(&mut theme.index) {
|
||||
_ => {}
|
||||
};
|
||||
},
|
||||
_ => {},
|
||||
let _ = f.read_to_end(&mut theme.index);
|
||||
}
|
||||
|
||||
// book.js
|
||||
match File::open(&src.join("book.js")) {
|
||||
Ok(mut f) => {
|
||||
if let Ok(mut f) = File::open(&src.join("book.js")) {
|
||||
theme.js.clear();
|
||||
match f.read_to_end(&mut theme.js){
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
let _ = f.read_to_end(&mut theme.js);
|
||||
}
|
||||
|
||||
// book.css
|
||||
match File::open(&src.join("book.css")) {
|
||||
Ok(mut f) => {
|
||||
if let Ok(mut f) = File::open(&src.join("book.css")) {
|
||||
theme.css.clear();
|
||||
match f.read_to_end(&mut theme.css) {
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
let _ = f.read_to_end(&mut theme.css);
|
||||
}
|
||||
|
||||
// highlight.js
|
||||
match File::open(&src.join("highlight.js")) {
|
||||
Ok(mut f) => {
|
||||
if let Ok(mut f) = File::open(&src.join("highlight.js")) {
|
||||
theme.highlight_js.clear();
|
||||
match f.read_to_end(&mut theme.highlight_js) {
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
let _ = f.read_to_end(&mut theme.highlight_js);
|
||||
}
|
||||
|
||||
// highlight.css
|
||||
match File::open(&src.join("highlight.css")) {
|
||||
Ok(mut f) => {
|
||||
if let Ok(mut f) = File::open(&src.join("highlight.css")) {
|
||||
theme.highlight_css.clear();
|
||||
match f.read_to_end(&mut theme.highlight_css) {
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
let _ = f.read_to_end(&mut theme.highlight_css);
|
||||
}
|
||||
|
||||
theme
|
||||
|
|
Loading…
Reference in New Issue