Finds the commonality between this and another `Pointer`.
(&'a self, other: &Self)
| 379 | |
| 380 | /// Finds the commonality between this and another `Pointer`. |
| 381 | pub fn intersection<'a>(&'a self, other: &Self) -> &'a Self { |
| 382 | if self.is_root() || other.is_root() { |
| 383 | return Self::root(); |
| 384 | } |
| 385 | let mut idx = 0; |
| 386 | for (a, b) in self.tokens().zip(other.tokens()) { |
| 387 | if a != b { |
| 388 | break; |
| 389 | } |
| 390 | idx += a.encoded().len() + 1; |
| 391 | } |
| 392 | self.split_at(idx).map_or(self, |(head, _)| head) |
| 393 | } |
| 394 | |
| 395 | /// Attempts to delete a `serde_json::Value` based upon the path in this |
| 396 | /// `Pointer`. |