Intersect this range with the given range and return the result. If the intersection is empty, then this returns `None`.
(&self, other: &Self)
| 363 | /// |
| 364 | /// If the intersection is empty, then this returns `None`. |
| 365 | fn intersect(&self, other: &Self) -> Option<Self> { |
| 366 | let lower = cmp::max(self.lower(), other.lower()); |
| 367 | let upper = cmp::min(self.upper(), other.upper()); |
| 368 | if lower <= upper { |
| 369 | Some(Self::create(lower, upper)) |
| 370 | } else { |
| 371 | None |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | /// Subtract the given range from this range and return the resulting |
| 376 | /// ranges. |