mirror of
https://github.com/nushell/nushell.git
synced 2025-02-16 10:32:29 +01:00
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:
parent
2ad68e3702
commit
b2c5dc204a
@ -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.");
|
||||
|
@ -790,11 +790,7 @@ impl EngineState {
|
||||
|
||||
/// Returns the configuration settings for command history or `None` if history is disabled
|
||||
pub fn history_config(&self) -> Option<HistoryConfig> {
|
||||
if self.history_enabled {
|
||||
Some(self.config.history)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.history_enabled.then(|| self.config.history)
|
||||
}
|
||||
|
||||
pub fn get_var(&self, var_id: VarId) -> &Variable {
|
||||
|
@ -168,13 +168,7 @@ impl ScopeFrame {
|
||||
self.overlays
|
||||
.iter()
|
||||
.position(|(n, _)| n == name)
|
||||
.and_then(|id| {
|
||||
if self.active_overlays.contains(&id) {
|
||||
Some(id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.filter(|id| self.active_overlays.contains(id))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user