summaryrefslogtreecommitdiff
path: root/src/model/ops.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-04 09:30:44 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-04 11:38:09 +0100
commiteb951c008beea502042db4a3a0e8d1f8b51f6f52 (patch)
tree9856ee4ed0222222669de10e616a580b2a60135e /src/model/ops.rs
parent33928a00dc58250e24da1dae4e5db17e7b598d70 (diff)
Style changes
Diffstat (limited to 'src/model/ops.rs')
-rw-r--r--src/model/ops.rs38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/model/ops.rs b/src/model/ops.rs
index ee126b03..9d55fa63 100644
--- a/src/model/ops.rs
+++ b/src/model/ops.rs
@@ -103,17 +103,17 @@ pub fn add(lhs: Value, rhs: Value) -> StrResult<Value> {
if let (Some(&a), Some(&b)) =
(a.downcast::<GenAlign>(), b.downcast::<GenAlign>())
{
- if a.axis() != b.axis() {
- Value::dynamic(match a.axis() {
- Axis::X => Axes { x: a, y: b },
- Axis::Y => Axes { x: b, y: a },
- })
- } else {
+ if a.axis() == b.axis() {
return Err(format!("cannot add two {:?} alignments", a.axis()));
}
- } else {
- mismatch!("cannot add {} and {}", a, b);
- }
+
+ return Ok(Value::dynamic(match a.axis() {
+ Axis::X => Axes { x: a, y: b },
+ Axis::Y => Axes { x: b, y: a },
+ }));
+ };
+
+ mismatch!("cannot add {} and {}", a, b);
}
(a, b) => mismatch!("cannot add {} and {}", a, b),
@@ -370,17 +370,11 @@ pub fn not_in(lhs: Value, rhs: Value) -> StrResult<Value> {
/// Test for containment.
pub fn contains(lhs: &Value, rhs: &Value) -> Option<bool> {
- Some(match (lhs, rhs) {
- (Str(a), Str(b)) => b.as_str().contains(a.as_str()),
- (Dyn(a), Str(b)) => {
- if let Some(regex) = a.downcast::<Regex>() {
- regex.is_match(b)
- } else {
- return Option::None;
- }
- }
- (Str(a), Dict(b)) => b.contains(a),
- (a, Array(b)) => b.contains(a),
- _ => return Option::None,
- })
+ match (lhs, rhs) {
+ (Str(a), Str(b)) => Some(b.as_str().contains(a.as_str())),
+ (Dyn(a), Str(b)) => a.downcast::<Regex>().map(|regex| regex.is_match(b)),
+ (Str(a), Dict(b)) => Some(b.contains(a)),
+ (a, Array(b)) => Some(b.contains(a)),
+ _ => Option::None,
+ }
}