(self, rhs: Value)
| 1567 | |
| 1568 | #[inline(always)] |
| 1569 | fn add(self, rhs: Value) -> Self::Output { |
| 1570 | match (self, rhs) { |
| 1571 | (Value::Int(l), Value::Int(r)) => l |
| 1572 | .checked_add(r) |
| 1573 | .ok_or_else(|| ExecutionError::Overflow("add", l.into(), r.into())) |
| 1574 | .map(Value::Int), |
| 1575 | |
| 1576 | (Value::UInt(l), Value::UInt(r)) => l |
| 1577 | .checked_add(r) |
| 1578 | .ok_or_else(|| ExecutionError::Overflow("add", l.into(), r.into())) |
| 1579 | .map(Value::UInt), |
| 1580 | |
| 1581 | (Value::Float(l), Value::Float(r)) => Value::Float(l + r).into(), |
| 1582 | |
| 1583 | (Value::List(mut l), Value::List(mut r)) => { |
| 1584 | { |
| 1585 | // If this is the only reference to `l`, we can append to it in place. |
| 1586 | // `l` is replaced with a clone otherwise. |
| 1587 | let l = Arc::make_mut(&mut l); |
| 1588 | |
| 1589 | // Likewise, if this is the only reference to `r`, we can move its values |
| 1590 | // instead of cloning them. |
| 1591 | match Arc::get_mut(&mut r) { |
| 1592 | Some(r) => l.append(r), |
| 1593 | None => l.extend(r.iter().cloned()), |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | Ok(Value::List(l)) |
| 1598 | } |
| 1599 | (Value::String(mut l), Value::String(r)) => { |
| 1600 | // If this is the only reference to `l`, we can append to it in place. |
| 1601 | // `l` is replaced with a clone otherwise. |
| 1602 | Arc::make_mut(&mut l).push_str(&r); |
| 1603 | Ok(Value::String(l)) |
| 1604 | } |
| 1605 | #[cfg(feature = "chrono")] |
| 1606 | (Value::Duration(l), Value::Duration(r)) => l |
| 1607 | .checked_add(&r) |
| 1608 | .ok_or_else(|| ExecutionError::Overflow("add", l.into(), r.into())) |
| 1609 | .map(Value::Duration), |
| 1610 | #[cfg(feature = "chrono")] |
| 1611 | (Value::Timestamp(l), Value::Duration(r)) => checked_op(TsOp::Add, &l, &r), |
| 1612 | #[cfg(feature = "chrono")] |
| 1613 | (Value::Duration(l), Value::Timestamp(r)) => r |
| 1614 | .checked_add_signed(l) |
| 1615 | .ok_or_else(|| ExecutionError::Overflow("add", l.into(), r.into())) |
| 1616 | .map(Value::Timestamp), |
| 1617 | (left, right) => Err(ExecutionError::UnsupportedBinaryOperator( |
| 1618 | "add", left, right, |
| 1619 | )), |
| 1620 | } |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | impl ops::Sub<Value> for Value { |
no test coverage detected