Style: move some Option if/else to method chains (#12285)

- **Use `bool::then` where it simplifies readability**
- **More debatable uses of `bool::then`**
- **Use `Option::filter` in `find_active_overlay`**
This commit is contained in:
Stefan Holderbach
2024-03-26 01:35:51 +01:00
committed by GitHub
parent 2ad68e3702
commit b2c5dc204a
3 changed files with 18 additions and 42 deletions

View File

@@ -68,16 +68,8 @@ impl Profiler {
duration_sec: 0.0,
depth: 0,
element_span: span,
element_output: if collect_values {
Some(Value::nothing(span))
} else {
None
},
expr: if collect_exprs {
Some("call".to_string())
} else {
None
},
element_output: collect_values.then(|| Value::nothing(span)),
expr: collect_exprs.then(|| "call".to_string()),
children: vec![],
};
@@ -141,11 +133,9 @@ impl Debugger for Profiler {
return;
};
let expr_opt = if self.collect_exprs {
Some(expr_to_string(engine_state, &element.expr.expr))
} else {
None
};
let expr_opt = self
.collect_exprs
.then(|| expr_to_string(engine_state, &element.expr.expr));
let new_id = ElementId(self.elements.len());
@@ -175,21 +165,17 @@ impl Debugger for Profiler {
let element_span = element.expr.span;
let out_opt = if self.collect_values {
Some(match result {
Ok((pipeline_data, _not_sure_what_this_is)) => match pipeline_data {
PipelineData::Value(val, ..) => val.clone(),
PipelineData::ListStream(..) => Value::string("list stream", element_span),
PipelineData::ExternalStream { .. } => {
Value::string("external stream", element_span)
}
_ => Value::nothing(element_span),
},
Err(e) => Value::error(e.clone(), element_span),
})
} else {
None
};
let out_opt = self.collect_values.then(|| match result {
Ok((pipeline_data, _not_sure_what_this_is)) => match pipeline_data {
PipelineData::Value(val, ..) => val.clone(),
PipelineData::ListStream(..) => Value::string("list stream", element_span),
PipelineData::ExternalStream { .. } => {
Value::string("external stream", element_span)
}
_ => Value::nothing(element_span),
},
Err(e) => Value::error(e.clone(), element_span),
});
let Some(last_element) = self.last_element_mut() else {
eprintln!("Profiler Error: Missing last element.");