use crate::prelude::*;
#[derive(Debug, Clone)]
pub struct NonSpecialPathSegments<'a>(Cow<'a, str>);
impl<'a> NonSpecialPathSegments<'a> {
pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {
Self(value.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn iter(&self) -> NonSpecialPathSegmentsIter<'_> {
self.into_iter()
}
pub fn get(&self, index: isize) -> Option<NonSpecialPathSegment<'_>> {
self.iter().neg_nth(index)
}
pub fn into_inner(self) -> Cow<'a, str> {
self.0
}
pub fn into_owned(self) -> NonSpecialPathSegments<'static> {
NonSpecialPathSegments(self.0.into_owned().into())
}
pub fn borrowed(&self) -> NonSpecialPathSegments<'_> {
NonSpecialPathSegments(Cow::Borrowed(&self.0))
}
}
impl<'a> From<Cow<'a, [u8]>> for NonSpecialPathSegments<'a> {
fn from(value: Cow<'a, [u8]>) -> Self {
let (_, value) = make_non_special_path_segments_bytes(value);
unsafe {
Self::new_unchecked(value)
}
}
}
impl<'a> From<PathSegments<'a>> for NonSpecialPathSegments<'a> {
fn from(value: PathSegments<'a>) -> Self {
match value {
PathSegments::File (x) => x.into(),
PathSegments::SpecialNotFile(x) => x.into(),
PathSegments::NonSpecial (x) => x,
}
}
}
impl<'a> From<FilePathSegments <'a>> for NonSpecialPathSegments<'a> {fn from(value: FilePathSegments <'a>) -> Self {Self(value.into_inner())}}
impl<'a> From<SpecialNotFilePathSegments<'a>> for NonSpecialPathSegments<'a> {fn from(value: SpecialNotFilePathSegments<'a>) -> Self {Self(value.into_inner())}}
impl<'a> From<PathSegment <'a>> for NonSpecialPathSegments<'a> {fn from(value: PathSegment <'a>) -> Self {Self(value.into_inner())}}
impl<'a> From<FilePathSegment <'a>> for NonSpecialPathSegments<'a> {fn from(value: FilePathSegment <'a>) -> Self {Self(value.into_inner())}}
impl<'a> From<SpecialNotFilePathSegment<'a>> for NonSpecialPathSegments<'a> {fn from(value: SpecialNotFilePathSegment<'a>) -> Self {Self(value.into_inner())}}
impl<'a> From<NonSpecialPathSegment <'a>> for NonSpecialPathSegments<'a> {fn from(value: NonSpecialPathSegment <'a>) -> Self {Self(value.into_inner())}}
impl<'a, 'b> Extend<NonSpecialPathSegment<'b>> for NonSpecialPathSegments<'a> {
fn extend<I: IntoIterator<Item = NonSpecialPathSegment<'b>>>(&mut self, iter: I) {
self.0.to_mut().extend(iter.into_iter().flat_map(|x| ["/".into(), x.into_inner()]))
}
}