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

Method split_front

src/pointer.rs:181–207  ·  view source on GitHub ↗

Splits the `Pointer` into the first `Token` and a remainder `Pointer`.

(&self)

Source from the content-addressed store, hash-verified

179
180 /// Splits the `Pointer` into the first `Token` and a remainder `Pointer`.
181 pub fn split_front(&self) -> Option<(Token, &Self)> {
182 if self.is_root() {
183 return None;
184 }
185 self.0[1..]
186 .find('/')
187 .map_or_else(
188 || {
189 (
190 // SAFETY: source pointer is encoded
191 unsafe { Token::from_encoded_unchecked(&self.0[1..]) },
192 Self::root(),
193 )
194 },
195 |idx| {
196 let (front, back) = self.0[1..].split_at(idx);
197 (
198 // SAFETY: source pointer is encoded
199 unsafe { Token::from_encoded_unchecked(front) },
200 // SAFETY: we split at a token boundary, so back is
201 // valid pointer.
202 unsafe { Self::new_unchecked(back) },
203 )
204 },
205 )
206 .into()
207 }
208
209 /// Splits the `Pointer` at the given index if the character at the index is
210 /// a separator slash (`'/'`), returning `Some((head, tail))`. Otherwise,

Callers 4

assign_valueFunction · 0.80
resolveMethod · 0.80
resolve_mutMethod · 0.80
qc_splitFunction · 0.80

Calls 2

is_rootMethod · 0.80
split_atMethod · 0.80

Tested by

no test coverage detected