Subtract the given range from this range and return the resulting ranges. If subtraction would result in an empty range, then no ranges are returned.
(&self, other: &Self)
| 378 | /// If subtraction would result in an empty range, then no ranges are |
| 379 | /// returned. |
| 380 | fn difference(&self, other: &Self) -> (Option<Self>, Option<Self>) { |
| 381 | if self.is_subset(other) { |
| 382 | return (None, None); |
| 383 | } |
| 384 | if self.is_intersection_empty(other) { |
| 385 | return (Some(self.clone()), None); |
| 386 | } |
| 387 | let add_lower = other.lower() > self.lower(); |
| 388 | let add_upper = other.upper() < self.upper(); |
| 389 | // We know this because !self.is_subset(other) and the ranges have |
| 390 | // a non-empty intersection. |
| 391 | assert!(add_lower || add_upper); |
| 392 | let mut ret = (None, None); |
| 393 | if add_lower { |
| 394 | let upper = other.lower().decrement(); |
| 395 | ret.0 = Some(Self::create(self.lower(), upper)); |
| 396 | } |
| 397 | if add_upper { |
| 398 | let lower = other.upper().increment(); |
| 399 | let range = Self::create(lower, self.upper()); |
| 400 | if ret.0.is_none() { |
| 401 | ret.0 = Some(range); |
| 402 | } else { |
| 403 | ret.1 = Some(range); |
| 404 | } |
| 405 | } |
| 406 | ret |
| 407 | } |
| 408 | |
| 409 | /// Compute the symmetric difference the given range from this range. This |
| 410 | /// returns the union of the two ranges minus its intersection. |
nothing calls this directly
no test coverage detected