Make ExternalHtml::load short-circuited.
This commit is contained in:
parent
7be14eea94
commit
ba20da1db7
1 changed files with 16 additions and 10 deletions
|
|
@ -30,16 +30,22 @@ pub struct ExternalHtml{
|
|||
impl ExternalHtml {
|
||||
pub fn load(in_header: &[String], before_content: &[String], after_content: &[String])
|
||||
-> Option<ExternalHtml> {
|
||||
match (load_external_files(in_header),
|
||||
load_external_files(before_content),
|
||||
load_external_files(after_content)) {
|
||||
(Some(ih), Some(bc), Some(ac)) => Some(ExternalHtml {
|
||||
in_header: ih,
|
||||
before_content: bc,
|
||||
after_content: ac
|
||||
}),
|
||||
_ => None
|
||||
}
|
||||
load_external_files(in_header)
|
||||
.and_then(|ih|
|
||||
load_external_files(before_content)
|
||||
.map(|bc| (ih, bc))
|
||||
)
|
||||
.and_then(|(ih, bc)|
|
||||
load_external_files(after_content)
|
||||
.map(|ac| (ih, bc, ac))
|
||||
)
|
||||
.map(|(ih, bc, ac)|
|
||||
ExternalHtml {
|
||||
in_header: ih,
|
||||
before_content: bc,
|
||||
after_content: ac,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue