diff --git a/crates/nu-cli/src/commands/group_by.rs b/crates/nu-cli/src/commands/group_by.rs index c793494420..e7b5c3ae97 100644 --- a/crates/nu-cli/src/commands/group_by.rs +++ b/crates/nu-cli/src/commands/group_by.rs @@ -237,10 +237,7 @@ pub fn group( crate::utils::data::group(&values, &Some(block), &name) } Grouper::ByColumn(None) => { - let block = Box::new(move |_, row: &Value| match as_string(row) { - Ok(group_key) => Ok(group_key), - Err(reason) => Err(reason), - }); + let block = Box::new(move |_, row: &Value| as_string(row)); crate::utils::data::group(&values, &Some(block), &name) } diff --git a/crates/nu-cli/src/data/dict.rs b/crates/nu-cli/src/data/dict.rs index bc7050676d..5be5c09043 100644 --- a/crates/nu-cli/src/data/dict.rs +++ b/crates/nu-cli/src/data/dict.rs @@ -54,14 +54,10 @@ impl DictionaryExt for Dictionary { } fn get_mut_data_by_key(&mut self, name: &str) -> Option<&mut Value> { - match self - .entries + self.entries .iter_mut() .find(|(desc_name, _)| *desc_name == name) - { - Some((_, v)) => Some(v), - None => None, - } + .map_or_else(|| None, |x| Some(x.1)) } fn insert_data_at_key(&mut self, name: &str, value: Value) { diff --git a/crates/nu-protocol/src/value.rs b/crates/nu-protocol/src/value.rs index 7c70f06184..6348b41e83 100644 --- a/crates/nu-protocol/src/value.rs +++ b/crates/nu-protocol/src/value.rs @@ -52,11 +52,8 @@ impl UntaggedValue { /// Get the corresponding descriptors (column names) associated with this value pub fn data_descriptors(&self) -> Vec { match self { - UntaggedValue::Primitive(_) => vec![], UntaggedValue::Row(columns) => columns.entries.keys().map(|x| x.to_string()).collect(), - UntaggedValue::Block(_) => vec![], - UntaggedValue::Table(_) => vec![], - UntaggedValue::Error(_) => vec![], + _ => vec![], } } diff --git a/crates/nu-source/src/meta.rs b/crates/nu-source/src/meta.rs index 42b8764ab6..1975a2434e 100644 --- a/crates/nu-source/src/meta.rs +++ b/crates/nu-source/src/meta.rs @@ -465,10 +465,7 @@ impl From<&Span> for Span { impl From> for Span { fn from(input: Option) -> Span { - match input { - None => Span::new(0, 0), - Some(span) => span, - } + input.unwrap_or_else(|| Span::new(0, 0)) } } @@ -635,9 +632,9 @@ impl Span { /// // make clean /// // ---- /// // (0,4) - /// // + /// // /// // ^(5,5) - /// + /// /// let make_span = Span::new(0,4); /// let clean_span = Span::new(5,5); /// diff --git a/crates/nu-source/src/pretty.rs b/crates/nu-source/src/pretty.rs index 7be1ce533d..20a177b6ce 100644 --- a/crates/nu-source/src/pretty.rs +++ b/crates/nu-source/src/pretty.rs @@ -249,10 +249,7 @@ impl DebugDocBuilder { } pub fn option(builder: Option) -> DebugDocBuilder { - match builder { - None => DebugDocBuilder::blank(), - Some(b) => b, - } + builder.unwrap_or_else(DebugDocBuilder::blank) } pub fn space() -> DebugDocBuilder {