flatten a match

This commit is contained in:
Irevoire 2021-11-09 00:49:13 +01:00
parent 15bd14297e
commit ef0d5a8240
No known key found for this signature in database
GPG Key ID: 7A6A970C96104F1B

View File

@ -45,28 +45,17 @@ pub fn parse_condition(input: Span) -> IResult<FilterCondition> {
let operator = alt((tag("<="), tag(">="), tag("!="), tag("<"), tag(">"), tag("=")));
let (input, (fid, op, value)) = tuple((parse_value, operator, cut(parse_value)))(input)?;
match *op.fragment() {
"=" => {
let k = FilterCondition::Condition { fid, op: Equal(value) };
Ok((input, k))
}
"!=" => {
let k = FilterCondition::Condition { fid, op: NotEqual(value) };
Ok((input, k))
}
">" | "<" | "<=" | ">=" => {
let k = match *op.fragment() {
">" => FilterCondition::Condition { fid, op: GreaterThan(value) },
"<" => FilterCondition::Condition { fid, op: LowerThan(value) },
"<=" => FilterCondition::Condition { fid, op: LowerThanOrEqual(value) },
">=" => FilterCondition::Condition { fid, op: GreaterThanOrEqual(value) },
_ => unreachable!(),
};
Ok((input, k))
}
let condition = match *op.fragment() {
"=" => FilterCondition::Condition { fid, op: Equal(value) },
"!=" => FilterCondition::Condition { fid, op: NotEqual(value) },
">" => FilterCondition::Condition { fid, op: GreaterThan(value) },
"<" => FilterCondition::Condition { fid, op: LowerThan(value) },
"<=" => FilterCondition::Condition { fid, op: LowerThanOrEqual(value) },
">=" => FilterCondition::Condition { fid, op: GreaterThanOrEqual(value) },
_ => unreachable!(),
}
};
Ok((input, condition))
}
/// to = value value TO value