MCPcopy Create free account
hub / github.com/chanced/jsonptr / intersection

Method intersection

src/pointer.rs:381–393  ·  view source on GitHub ↗

Finds the commonality between this and another `Pointer`.

(&'a self, other: &Self)

Source from the content-addressed store, hash-verified

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`.

Callers 2

qc_intersectionFunction · 0.80
intersectionFunction · 0.80

Calls 5

is_rootMethod · 0.80
tokensMethod · 0.80
lenMethod · 0.80
encodedMethod · 0.80
split_atMethod · 0.80

Tested by 1

intersectionFunction · 0.64