mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 18:03:51 +01:00
Match cleanup (#2294)
* Delete unnecessary match * Use `unwrap_or_else()` * Whitespace was trim on file save * Use `map_or_else()` * Use a default to group all match arms with same output * Clippy made me do it
This commit is contained in:
parent
3a7869b422
commit
eeb9b4edcb
@ -237,10 +237,7 @@ pub fn group(
|
|||||||
crate::utils::data::group(&values, &Some(block), &name)
|
crate::utils::data::group(&values, &Some(block), &name)
|
||||||
}
|
}
|
||||||
Grouper::ByColumn(None) => {
|
Grouper::ByColumn(None) => {
|
||||||
let block = Box::new(move |_, row: &Value| match as_string(row) {
|
let block = Box::new(move |_, row: &Value| as_string(row));
|
||||||
Ok(group_key) => Ok(group_key),
|
|
||||||
Err(reason) => Err(reason),
|
|
||||||
});
|
|
||||||
|
|
||||||
crate::utils::data::group(&values, &Some(block), &name)
|
crate::utils::data::group(&values, &Some(block), &name)
|
||||||
}
|
}
|
||||||
|
@ -54,14 +54,10 @@ impl DictionaryExt for Dictionary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_mut_data_by_key(&mut self, name: &str) -> Option<&mut Value> {
|
fn get_mut_data_by_key(&mut self, name: &str) -> Option<&mut Value> {
|
||||||
match self
|
self.entries
|
||||||
.entries
|
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|(desc_name, _)| *desc_name == name)
|
.find(|(desc_name, _)| *desc_name == name)
|
||||||
{
|
.map_or_else(|| None, |x| Some(x.1))
|
||||||
Some((_, v)) => Some(v),
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_data_at_key(&mut self, name: &str, value: Value) {
|
fn insert_data_at_key(&mut self, name: &str, value: Value) {
|
||||||
|
@ -52,11 +52,8 @@ impl UntaggedValue {
|
|||||||
/// Get the corresponding descriptors (column names) associated with this value
|
/// Get the corresponding descriptors (column names) associated with this value
|
||||||
pub fn data_descriptors(&self) -> Vec<String> {
|
pub fn data_descriptors(&self) -> Vec<String> {
|
||||||
match self {
|
match self {
|
||||||
UntaggedValue::Primitive(_) => vec![],
|
|
||||||
UntaggedValue::Row(columns) => columns.entries.keys().map(|x| x.to_string()).collect(),
|
UntaggedValue::Row(columns) => columns.entries.keys().map(|x| x.to_string()).collect(),
|
||||||
UntaggedValue::Block(_) => vec![],
|
_ => vec![],
|
||||||
UntaggedValue::Table(_) => vec![],
|
|
||||||
UntaggedValue::Error(_) => vec![],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,10 +465,7 @@ impl From<&Span> for Span {
|
|||||||
|
|
||||||
impl From<Option<Span>> for Span {
|
impl From<Option<Span>> for Span {
|
||||||
fn from(input: Option<Span>) -> Span {
|
fn from(input: Option<Span>) -> Span {
|
||||||
match input {
|
input.unwrap_or_else(|| Span::new(0, 0))
|
||||||
None => Span::new(0, 0),
|
|
||||||
Some(span) => span,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,9 +632,9 @@ impl Span {
|
|||||||
/// // make clean
|
/// // make clean
|
||||||
/// // ----
|
/// // ----
|
||||||
/// // (0,4)
|
/// // (0,4)
|
||||||
/// //
|
/// //
|
||||||
/// // ^(5,5)
|
/// // ^(5,5)
|
||||||
///
|
///
|
||||||
/// let make_span = Span::new(0,4);
|
/// let make_span = Span::new(0,4);
|
||||||
/// let clean_span = Span::new(5,5);
|
/// let clean_span = Span::new(5,5);
|
||||||
///
|
///
|
||||||
|
@ -249,10 +249,7 @@ impl DebugDocBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn option(builder: Option<DebugDocBuilder>) -> DebugDocBuilder {
|
pub fn option(builder: Option<DebugDocBuilder>) -> DebugDocBuilder {
|
||||||
match builder {
|
builder.unwrap_or_else(DebugDocBuilder::blank)
|
||||||
None => DebugDocBuilder::blank(),
|
|
||||||
Some(b) => b,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn space() -> DebugDocBuilder {
|
pub fn space() -> DebugDocBuilder {
|
||||||
|
Loading…
Reference in New Issue
Block a user