better_url/parts/path/segment/
non_special.rs1use crate::prelude::*;
4
5#[derive(Debug, Clone)]
7pub struct NonSpecialPathSegment<'a>(Cow<'a, str>);
8
9impl<'a> NonSpecialPathSegment<'a> {
10 pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {
14 Self(value.into())
15 }
16
17 pub fn as_str(&self) -> &str {
19 &self.0
20 }
21
22 pub fn decode(self) -> Cow<'a, [u8]> {
24 let (_, value) = percent_decode(self.0);
25
26 value
27 }
28
29 pub fn try_decode(self) -> Result<Cow<'a, str>, (std::str::Utf8Error, Cow<'a, [u8]>)> {
33 let (_, value) = try_percent_decode(self.into_inner())?;
34
35 Ok(value)
36 }
37
38 pub fn lossy_decode(self) -> Cow<'a, str> {
40 let (_, value) = lossy_percent_decode(self.into_inner());
41
42 value
43 }
44
45
46
47 pub fn is_drive_letter (&self) -> bool {path_segment_is_drive_letter (self.as_str())}
48 pub fn is_normalized_drive_letter (&self) -> bool {path_segment_is_normalized_drive_letter (self.as_str())}
49 pub fn is_non_normalized_drive_letter(&self) -> bool {path_segment_is_non_normalized_drive_letter(self.as_str())}
50 pub fn is_single_dot (&self) -> bool {path_segment_is_single_dot (self.as_str())}
51 pub fn is_double_dot (&self) -> bool {path_segment_is_double_dot (self.as_str())}
52
53
54
55 pub fn into_inner(self) -> Cow<'a, str> {
57 self.0
58 }
59
60 pub fn into_owned(self) -> NonSpecialPathSegment<'static> {
62 NonSpecialPathSegment(self.0.into_owned().into())
63 }
64
65 pub fn borrowed(&self) -> NonSpecialPathSegment<'_> {
67 NonSpecialPathSegment(Cow::Borrowed(&self.0))
68 }
69}
70
71
72
73impl<'a> From<Cow<'a, [u8]>> for NonSpecialPathSegment<'a> {
74 fn from(value: Cow<'a, [u8]>) -> Self {
75 let (_, value) = make_non_special_path_segment_bytes(value);
76
77 unsafe {
78 Self::new_unchecked(value)
79 }
80 }
81}
82
83
84
85impl<'a> From<PathSegment<'a>> for NonSpecialPathSegment<'a> {
86 fn from(value: PathSegment<'a>) -> Self {
87 match value {
88 PathSegment::File (x) => x.into(),
89 PathSegment::SpecialNotFile(x) => x.into(),
90 PathSegment::NonSpecial (x) => x,
91 }
92 }
93}
94
95impl<'a> From<SpecialNotFilePathSegment<'a>> for NonSpecialPathSegment<'a> {fn from(value: SpecialNotFilePathSegment<'a>) -> Self {Self(value.into_inner())}}
96impl<'a> From<FilePathSegment <'a>> for NonSpecialPathSegment<'a> {fn from(value: FilePathSegment <'a>) -> Self {Self(value.into_inner())}}