Splits the `Pointer` into the first `Token` and a remainder `Pointer`.
(&self)
| 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, |
no test coverage detected