better_url/parts/path/segments/
special_not_file.rs1use crate::prelude::*;
4
5#[derive(Debug, Clone)]
21pub struct SpecialNotFilePathSegments<'a>(Cow<'a, str>);
22
23impl<'a> SpecialNotFilePathSegments<'a> {
24 pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {
28 Self(value.into())
29 }
30
31 pub fn as_str(&self) -> &str {
33 &self.0
34 }
35
36
37
38 pub fn iter(&self) -> SpecialNotFilePathSegmentsIter<'_> {
40 self.into_iter()
41 }
42
43 pub fn get(&self, index: isize) -> Option<SpecialNotFilePathSegment<'_>> {
45 self.iter().neg_nth(index)
46 }
47
48
49
50 pub fn into_inner(self) -> Cow<'a, str> {
52 self.0
53 }
54
55 pub fn into_owned(self) -> SpecialNotFilePathSegments<'static> {
57 SpecialNotFilePathSegments(self.0.into_owned().into())
58 }
59
60 pub fn borrowed(&self) -> SpecialNotFilePathSegments<'_> {
62 SpecialNotFilePathSegments(Cow::Borrowed(&self.0))
63 }
64}
65
66
67
68impl<'a> From<Cow<'a, [u8]>> for SpecialNotFilePathSegments<'a> {
69 fn from(value: Cow<'a, [u8]>) -> Self {
70 let (_, value) = make_special_not_file_path_segments_bytes(value);
71
72 unsafe {
73 Self::new_unchecked(value)
74 }
75 }
76}
77
78
79
80impl<'a> From<PathSegments<'a>> for SpecialNotFilePathSegments<'a> {
81 fn from(value: PathSegments<'a>) -> Self {
82 match value {
83 PathSegments::File (x) => x.into(),
84 PathSegments::SpecialNotFile(x) => x,
85 PathSegments::NonSpecial (x) => x.into(),
86 }
87 }
88}
89
90impl<'a> From<FilePathSegments <'a>> for SpecialNotFilePathSegments<'a> {fn from(value: FilePathSegments <'a>) -> Self {Self( value.into_inner() )}}
91impl<'a> From<NonSpecialPathSegments<'a>> for SpecialNotFilePathSegments<'a> {fn from(value: NonSpecialPathSegments<'a>) -> Self {Self(forward_slashes(value.into_inner()).1)}}
92
93impl<'a> From<PathSegment <'a>> for SpecialNotFilePathSegments<'a> {fn from(value: PathSegment <'a>) -> Self {Self( value.into_inner() )}}
94impl<'a> From<FilePathSegment <'a>> for SpecialNotFilePathSegments<'a> {fn from(value: FilePathSegment <'a>) -> Self {Self( value.into_inner() )}}
95impl<'a> From<SpecialNotFilePathSegment<'a>> for SpecialNotFilePathSegments<'a> {fn from(value: SpecialNotFilePathSegment<'a>) -> Self {Self( value.into_inner() )}}
96impl<'a> From<NonSpecialPathSegment <'a>> for SpecialNotFilePathSegments<'a> {fn from(value: NonSpecialPathSegment <'a>) -> Self {Self(forward_slashes(value.into_inner()).1)}}
97
98impl<'a, 'b> Extend<SpecialNotFilePathSegment<'b>> for SpecialNotFilePathSegments<'a> {
99 fn extend<I: IntoIterator<Item = SpecialNotFilePathSegment<'b>>>(&mut self, iter: I) {
100 self.0.to_mut().extend(iter.into_iter().flat_map(|x| ["/".into(), x.into_inner()]))
101 }
102}