Use matches!() for true/false returning match statements (#2176)

This commit is contained in:
Joseph T. Lyons
2020-07-14 20:11:41 -04:00
committed by GitHub
parent 17e6c53b62
commit 0934410b38
11 changed files with 19 additions and 70 deletions

View File

@ -74,13 +74,10 @@ impl WholeStreamCommand for Each {
}
fn is_expanded_it_usage(head: &SpannedExpression) -> bool {
match &*head {
SpannedExpression {
expr: Expression::Synthetic(Synthetic::String(s)),
..
} if s == "expanded-each" => true,
_ => false,
}
matches!(&*head, SpannedExpression {
expr: Expression::Synthetic(Synthetic::String(s)),
..
} if s == "expanded-each")
}
pub async fn process_row(

View File

@ -90,10 +90,7 @@ impl RangeIterator {
curr: range.from.0.item,
end: range.to.0.item,
tag,
is_end_inclusive: match range.to.1 {
RangeInclusion::Inclusive => true,
RangeInclusion::Exclusive => false,
},
is_end_inclusive: matches!(range.to.1, RangeInclusion::Inclusive),
is_done: false,
}
}

View File

@ -100,10 +100,7 @@ impl WholeStreamCommand for KeepUntil {
.await;
trace!("RESULT = {:?}", result);
match result {
Ok(ref v) if v.is_true() => false,
_ => true,
}
!matches!(result, Ok(ref v) if v.is_true())
}
})
.to_output_stream())

View File

@ -100,10 +100,7 @@ impl WholeStreamCommand for KeepWhile {
.await;
trace!("RESULT = {:?}", result);
match result {
Ok(ref v) if v.is_true() => true,
_ => false,
}
matches!(result, Ok(ref v) if v.is_true())
}
})
.to_output_stream())

View File

@ -99,10 +99,7 @@ impl WholeStreamCommand for SkipUntil {
.await;
trace!("RESULT = {:?}", result);
match result {
Ok(ref v) if v.is_true() => false, // stop skipping
_ => true,
}
!matches!(result, Ok(ref v) if v.is_true())
}
})
.to_output_stream())

View File

@ -99,10 +99,7 @@ impl WholeStreamCommand for SkipWhile {
.await;
trace!("RESULT = {:?}", result);
match result {
Ok(ref v) if v.is_true() => true,
_ => false,
}
matches!(result, Ok(ref v) if v.is_true())
}
})
.to_output_stream())

View File

@ -38,10 +38,7 @@ fn signature_dict(signature: Signature, tag: impl Into<Tag>) -> Value {
let mut sig = TaggedListBuilder::new(&tag);
for arg in signature.positional.iter() {
let is_required = match arg.0 {
PositionalType::Mandatory(_, _) => true,
PositionalType::Optional(_, _) => false,
};
let is_required = matches!(arg.0, PositionalType::Mandatory(_, _));
sig.push_value(for_spec(arg.0.name(), "argument", is_required, &tag));
}

View File

@ -8,10 +8,7 @@ use nu_protocol::{UntaggedValue, Value};
use std::path::{Component, Path, PathBuf};
fn is_value_tagged_dir(value: &Value) -> bool {
match &value.value {
UntaggedValue::Row(_) | UntaggedValue::Table(_) => true,
_ => false,
}
matches!(&value.value, UntaggedValue::Row(_) | UntaggedValue::Table(_))
}
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]