MCPcopy Create free account
hub / github.com/calfonso/rusternetes / split_path

Function split_path

crates/api-server/src/patch.rs:626–644  ·  view source on GitHub ↗

Split a path into parent path and final key

(path: &str)

Source from the content-addressed store, hash-verified

624
625/// Split a path into parent path and final key
626fn split_path(path: &str) -> Result<(&str, &str), PatchError> {
627 if path.is_empty() || path == "/" {
628 return Err(PatchError::InvalidPatch(
629 "Cannot split root path".to_string(),
630 ));
631 }
632
633 let last_slash = path
634 .rfind('/')
635 .ok_or_else(|| PatchError::InvalidPatch(format!("Path missing '/': {}", path)))?;
636 let parent = if last_slash == 0 {
637 "/"
638 } else {
639 &path[..last_slash]
640 };
641 let key = &path[last_slash + 1..];
642
643 Ok((parent, key))
644}
645
646#[cfg(test)]
647mod tests {

Callers 3

add_operationFunction · 0.85
remove_operationFunction · 0.85
replace_operationFunction · 0.85

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected