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

Method pop_front

src/pointer.rs:974–988  ·  view source on GitHub ↗

Removes and returns the first `Token` in the `Pointer` if it exists.

(&mut self)

Source from the content-addressed store, hash-verified

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 {

Callers 3

qc_pop_and_pushFunction · 0.80
qc_splitFunction · 0.80

Calls 1

is_rootMethod · 0.80

Tested by 1