better_url/parts/path/entire/segmented/file/
remove.rs1use crate::prelude::*;
4
5impl FilePath<'_> {
6 #[expect(clippy::missing_panics_doc, reason = "Can't happen.")]
10 pub fn pop(&mut self) -> Result<bool, SetPathError> {
11 match self.0.memrchr(b'/').expect("???") {
12 0 => Err(CantBeEmpty)?,
13 x => unsafe {self.0.truncate_unchecked(x)}
14 }
15
16 Ok(true)
17 }
18
19 pub fn pop_if_empty(&mut self) -> Result<bool, SetPathError> {
23 Ok(match self.as_str().as_bytes() {
24 [ b'/'] => Err(CantBeEmpty)?,
25 [x @ .., b'/'] => {
26 unsafe {
27 self.0.truncate_unchecked(x.len())
28 }
29
30 true
31 },
32 _ => false
33 })
34 }
35
36 pub fn remove(&mut self, index: isize) -> Result<bool, SetPathError> {
40 Ok(match self.get_str(index) {
41 Some(temp) => {
42 let mut range = self.as_str().my_substr_range(temp);
43 range.start -= 1;
44
45 if range.len() == self.len() {
46 Err(CantBeEmpty)?;
47 }
48
49 self.0.replace_range(range, "");
50
51 true
52 },
53 None => false
54 })
55 }
56}