mirror of
https://github.com/nushell/nushell.git
synced 2025-04-17 09:48:19 +02: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,
|
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.");
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user