forked from extern/nushell
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 {
|
fn is_expanded_it_usage(head: &SpannedExpression) -> bool {
|
||||||
match &*head {
|
matches!(&*head, SpannedExpression {
|
||||||
SpannedExpression {
|
expr: Expression::Synthetic(Synthetic::String(s)),
|
||||||
expr: Expression::Synthetic(Synthetic::String(s)),
|
..
|
||||||
..
|
} if s == "expanded-each")
|
||||||
} if s == "expanded-each" => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn process_row(
|
pub async fn process_row(
|
||||||
|
@ -90,10 +90,7 @@ impl RangeIterator {
|
|||||||
curr: range.from.0.item,
|
curr: range.from.0.item,
|
||||||
end: range.to.0.item,
|
end: range.to.0.item,
|
||||||
tag,
|
tag,
|
||||||
is_end_inclusive: match range.to.1 {
|
is_end_inclusive: matches!(range.to.1, RangeInclusion::Inclusive),
|
||||||
RangeInclusion::Inclusive => true,
|
|
||||||
RangeInclusion::Exclusive => false,
|
|
||||||
},
|
|
||||||
is_done: false,
|
is_done: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,10 +100,7 @@ impl WholeStreamCommand for KeepUntil {
|
|||||||
.await;
|
.await;
|
||||||
trace!("RESULT = {:?}", result);
|
trace!("RESULT = {:?}", result);
|
||||||
|
|
||||||
match result {
|
!matches!(result, Ok(ref v) if v.is_true())
|
||||||
Ok(ref v) if v.is_true() => false,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_output_stream())
|
||||||
|
@ -100,10 +100,7 @@ impl WholeStreamCommand for KeepWhile {
|
|||||||
.await;
|
.await;
|
||||||
trace!("RESULT = {:?}", result);
|
trace!("RESULT = {:?}", result);
|
||||||
|
|
||||||
match result {
|
matches!(result, Ok(ref v) if v.is_true())
|
||||||
Ok(ref v) if v.is_true() => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_output_stream())
|
||||||
|
@ -99,10 +99,7 @@ impl WholeStreamCommand for SkipUntil {
|
|||||||
.await;
|
.await;
|
||||||
trace!("RESULT = {:?}", result);
|
trace!("RESULT = {:?}", result);
|
||||||
|
|
||||||
match result {
|
!matches!(result, Ok(ref v) if v.is_true())
|
||||||
Ok(ref v) if v.is_true() => false, // stop skipping
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_output_stream())
|
||||||
|
@ -99,10 +99,7 @@ impl WholeStreamCommand for SkipWhile {
|
|||||||
.await;
|
.await;
|
||||||
trace!("RESULT = {:?}", result);
|
trace!("RESULT = {:?}", result);
|
||||||
|
|
||||||
match result {
|
matches!(result, Ok(ref v) if v.is_true())
|
||||||
Ok(ref v) if v.is_true() => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_output_stream())
|
||||||
|
@ -38,10 +38,7 @@ fn signature_dict(signature: Signature, tag: impl Into<Tag>) -> Value {
|
|||||||
let mut sig = TaggedListBuilder::new(&tag);
|
let mut sig = TaggedListBuilder::new(&tag);
|
||||||
|
|
||||||
for arg in signature.positional.iter() {
|
for arg in signature.positional.iter() {
|
||||||
let is_required = match arg.0 {
|
let is_required = matches!(arg.0, PositionalType::Mandatory(_, _));
|
||||||
PositionalType::Mandatory(_, _) => true,
|
|
||||||
PositionalType::Optional(_, _) => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
sig.push_value(for_spec(arg.0.name(), "argument", is_required, &tag));
|
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};
|
use std::path::{Component, Path, PathBuf};
|
||||||
|
|
||||||
fn is_value_tagged_dir(value: &Value) -> bool {
|
fn is_value_tagged_dir(value: &Value) -> bool {
|
||||||
match &value.value {
|
matches!(&value.value, UntaggedValue::Row(_) | UntaggedValue::Table(_))
|
||||||
UntaggedValue::Row(_) | UntaggedValue::Table(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
|
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||||
|
@ -265,13 +265,7 @@ impl ExternalCommand {
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let Path { head, .. } = &**path;
|
let Path { head, .. } = &**path;
|
||||||
match head {
|
matches!(head, SpannedExpression{expr: Expression::Variable(Variable::It(_)), ..})
|
||||||
SpannedExpression {
|
|
||||||
expr: Expression::Variable(Variable::It(_)),
|
|
||||||
..
|
|
||||||
} => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
})
|
})
|
||||||
@ -1352,10 +1346,7 @@ impl NamedArguments {
|
|||||||
pub fn switch_present(&self, switch: &str) -> bool {
|
pub fn switch_present(&self, switch: &str) -> bool {
|
||||||
self.named
|
self.named
|
||||||
.get(switch)
|
.get(switch)
|
||||||
.map(|t| match t {
|
.map(|t| matches!(t, NamedValue::PresentSwitch(_)))
|
||||||
NamedValue::PresentSwitch(_) => true,
|
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,18 +77,12 @@ impl UntaggedValue {
|
|||||||
|
|
||||||
/// Returns true if this value represents boolean true
|
/// Returns true if this value represents boolean true
|
||||||
pub fn is_true(&self) -> bool {
|
pub fn is_true(&self) -> bool {
|
||||||
match self {
|
matches!(self, UntaggedValue::Primitive(Primitive::Boolean(true)))
|
||||||
UntaggedValue::Primitive(Primitive::Boolean(true)) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value represents a table
|
/// Returns true if this value represents a table
|
||||||
pub fn is_table(&self) -> bool {
|
pub fn is_table(&self) -> bool {
|
||||||
match self {
|
matches!(self, UntaggedValue::Table(_))
|
||||||
UntaggedValue::Table(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the value represents something other than Nothing
|
/// Returns true if the value represents something other than Nothing
|
||||||
@ -98,18 +92,12 @@ impl UntaggedValue {
|
|||||||
|
|
||||||
/// Returns true if the value represents Nothing
|
/// Returns true if the value represents Nothing
|
||||||
pub fn is_none(&self) -> bool {
|
pub fn is_none(&self) -> bool {
|
||||||
match self {
|
matches!(self, UntaggedValue::Primitive(Primitive::Nothing))
|
||||||
UntaggedValue::Primitive(Primitive::Nothing) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the value represents an error
|
/// Returns true if the value represents an error
|
||||||
pub fn is_error(&self) -> bool {
|
pub fn is_error(&self) -> bool {
|
||||||
match self {
|
matches!(self, UntaggedValue::Error(_err))
|
||||||
UntaggedValue::Error(_err) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Expect this value to be an error and return it
|
/// 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
|
/// View the Value as a Primitive value, if possible
|
||||||
pub fn is_primitive(&self) -> bool {
|
pub fn is_primitive(&self) -> bool {
|
||||||
match &self.value {
|
matches!(&self.value, UntaggedValue::Primitive(_))
|
||||||
UntaggedValue::Primitive(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// View the Value as unsigned 64-bit, if possible
|
/// View the Value as unsigned 64-bit, if possible
|
||||||
|
@ -264,10 +264,7 @@ impl DebugDocBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
match &self.inner.1 {
|
matches!(&self.inner.1, pretty::Doc::Nil)
|
||||||
pretty::Doc::Nil => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn or(self, doc: DebugDocBuilder) -> DebugDocBuilder {
|
pub fn or(self, doc: DebugDocBuilder) -> DebugDocBuilder {
|
||||||
|
Loading…
Reference in New Issue
Block a user