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

Method split_at

src/pointer.rs:232–239  ·  view source on GitHub ↗

Splits the `Pointer` at the given index if the character at the index is a separator slash (`'/'`), returning `Some((head, tail))`. Otherwise, returns `None`. For the following JSON Pointer, the following splits are possible (0, 4, 8): ```text /foo/bar/baz ↑ ↑ ↑ 0 4 8 ``` All other indices will return `None`. ## Example ```rust # use jsonptr::Pointer; let ptr = Pointer::from_static("/fo

(&self, offset: usize)

Source from the content-addressed store, hash-verified

230 /// assert_eq!(ptr.split_at(3), None);
231 /// ```
232 pub fn split_at(&self, offset: usize) -> Option<(&Self, &Self)> {
233 if self.0.as_bytes().get(offset).copied() != Some(b'/') {
234 return None;
235 }
236 let (head, tail) = self.0.split_at(offset);
237 // SAFETY: we split at a token boundary, so head and tail are valid pointers
238 unsafe { Some((Self::new_unchecked(head), Self::new_unchecked(tail))) }
239 }
240
241 /// Splits the `Pointer` into the parent path and the last `Token`.
242 pub fn split_back(&self) -> Option<(&Self, Token)> {

Callers 2

split_frontMethod · 0.80
intersectionMethod · 0.80

Calls 1

getMethod · 0.45

Tested by

no test coverage detected