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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 42 deletions

View File

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

View File

@ -790,11 +790,7 @@ impl EngineState {
/// Returns the configuration settings for command history or `None` if history is disabled /// Returns the configuration settings for command history or `None` if history is disabled
pub fn history_config(&self) -> Option<HistoryConfig> { pub fn history_config(&self) -> Option<HistoryConfig> {
if self.history_enabled { self.history_enabled.then(|| self.config.history)
Some(self.config.history)
} else {
None
}
} }
pub fn get_var(&self, var_id: VarId) -> &Variable { pub fn get_var(&self, var_id: VarId) -> &Variable {

View File

@ -168,13 +168,7 @@ impl ScopeFrame {
self.overlays self.overlays
.iter() .iter()
.position(|(n, _)| n == name) .position(|(n, _)| n == name)
.and_then(|id| { .filter(|id| self.active_overlays.contains(id))
if self.active_overlays.contains(&id) {
Some(id)
} else {
None
}
})
} }
} }