Removes and returns the first `Token` in the `Pointer` if it exists.
(&mut self)
| 972 | |
| 973 | /// Removes and returns the first `Token` in the `Pointer` if it exists. |
| 974 | pub fn pop_front(&mut self) -> Option<Token<'static>> { |
| 975 | (!self.is_root()).then(|| { |
| 976 | // if not root, must contain at least one `/` |
| 977 | let mut token = if let Some(idx) = self.0[1..].find('/') { |
| 978 | let token = self.0.split_off(idx + 1); |
| 979 | core::mem::replace(&mut self.0, token) |
| 980 | } else { |
| 981 | core::mem::take(&mut self.0) |
| 982 | }; |
| 983 | // remove leading `/` |
| 984 | token.remove(0); |
| 985 | // SAFETY: source pointer is encoded |
| 986 | unsafe { Token::from_encoded_unchecked(token) } |
| 987 | }) |
| 988 | } |
| 989 | |
| 990 | /// Merges two `Pointer`s by appending `other` onto `self`. |
| 991 | pub fn append<P: AsRef<Pointer>>(&mut self, other: P) -> &PointerBuf { |