mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +01:00
Use matches!()
for true/false returning match statements (#2176)
This commit is contained in:
parent
17e6c53b62
commit
0934410b38
@ -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(
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
|
@ -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())
|
||||
|
@ -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())
|
||||
|
@ -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())
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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)]
|
||||
|
@ -265,13 +265,7 @@ impl ExternalCommand {
|
||||
..
|
||||
} => {
|
||||
let Path { head, .. } = &**path;
|
||||
match head {
|
||||
SpannedExpression {
|
||||
expr: Expression::Variable(Variable::It(_)),
|
||||
..
|
||||
} => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(head, SpannedExpression{expr: Expression::Variable(Variable::It(_)), ..})
|
||||
}
|
||||
_ => false,
|
||||
})
|
||||
@ -1352,10 +1346,7 @@ impl NamedArguments {
|
||||
pub fn switch_present(&self, switch: &str) -> bool {
|
||||
self.named
|
||||
.get(switch)
|
||||
.map(|t| match t {
|
||||
NamedValue::PresentSwitch(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
.map(|t| matches!(t, NamedValue::PresentSwitch(_)))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
@ -77,18 +77,12 @@ impl UntaggedValue {
|
||||
|
||||
/// Returns true if this value represents boolean true
|
||||
pub fn is_true(&self) -> bool {
|
||||
match self {
|
||||
UntaggedValue::Primitive(Primitive::Boolean(true)) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, UntaggedValue::Primitive(Primitive::Boolean(true)))
|
||||
}
|
||||
|
||||
/// Returns true if this value represents a table
|
||||
pub fn is_table(&self) -> bool {
|
||||
match self {
|
||||
UntaggedValue::Table(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, UntaggedValue::Table(_))
|
||||
}
|
||||
|
||||
/// Returns true if the value represents something other than Nothing
|
||||
@ -98,18 +92,12 @@ impl UntaggedValue {
|
||||
|
||||
/// Returns true if the value represents Nothing
|
||||
pub fn is_none(&self) -> bool {
|
||||
match self {
|
||||
UntaggedValue::Primitive(Primitive::Nothing) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, UntaggedValue::Primitive(Primitive::Nothing))
|
||||
}
|
||||
|
||||
/// Returns true if the value represents an error
|
||||
pub fn is_error(&self) -> bool {
|
||||
match self {
|
||||
UntaggedValue::Error(_err) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, UntaggedValue::Error(_err))
|
||||
}
|
||||
|
||||
/// Expect this value to be an error and return it
|
||||
@ -341,10 +329,7 @@ impl Value {
|
||||
|
||||
/// View the Value as a Primitive value, if possible
|
||||
pub fn is_primitive(&self) -> bool {
|
||||
match &self.value {
|
||||
UntaggedValue::Primitive(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(&self.value, UntaggedValue::Primitive(_))
|
||||
}
|
||||
|
||||
/// View the Value as unsigned 64-bit, if possible
|
||||
|
@ -264,10 +264,7 @@ impl DebugDocBuilder {
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
match &self.inner.1 {
|
||||
pretty::Doc::Nil => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(&self.inner.1, pretty::Doc::Nil)
|
||||
}
|
||||
|
||||
pub fn or(self, doc: DebugDocBuilder) -> DebugDocBuilder {
|
||||
|
Loading…
Reference in New Issue
Block a user