diff --git a/crates/nu-protocol/src/debugger/profiler.rs b/crates/nu-protocol/src/debugger/profiler.rs index f7645db497..68a5e8ea97 100644 --- a/crates/nu-protocol/src/debugger/profiler.rs +++ b/crates/nu-protocol/src/debugger/profiler.rs @@ -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."); diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index a54edac594..a53e4c0db9 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -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 { - 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 { diff --git a/crates/nu-protocol/src/engine/overlay.rs b/crates/nu-protocol/src/engine/overlay.rs index 96573a7f50..e396e30c21 100644 --- a/crates/nu-protocol/src/engine/overlay.rs +++ b/crates/nu-protocol/src/engine/overlay.rs @@ -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)) } }