use crate::prelude::*;
#[derive(Debug, Clone)]
pub struct NonSpecialPathSegment<'a>(Cow<'a, str>);
impl<'a> NonSpecialPathSegment<'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 decode(self) -> Cow<'a, [u8]> {
let (_, value) = percent_decode(self.0);
value
}
pub fn try_decode(self) -> Result<Cow<'a, str>, (std::str::Utf8Error, Cow<'a, [u8]>)> {
let (_, value) = try_percent_decode(self.into_inner())?;
Ok(value)
}
pub fn lossy_decode(self) -> Cow<'a, str> {
let (_, value) = lossy_percent_decode(self.into_inner());
value
}
pub fn is_drive_letter (&self) -> bool {path_segment_is_drive_letter (self.as_str())}
pub fn is_normalized_drive_letter (&self) -> bool {path_segment_is_normalized_drive_letter (self.as_str())}
pub fn is_non_normalized_drive_letter(&self) -> bool {path_segment_is_non_normalized_drive_letter(self.as_str())}
pub fn is_single_dot (&self) -> bool {path_segment_is_single_dot (self.as_str())}
pub fn is_double_dot (&self) -> bool {path_segment_is_double_dot (self.as_str())}
pub fn into_inner(self) -> Cow<'a, str> {
self.0
}
pub fn into_owned(self) -> NonSpecialPathSegment<'static> {
NonSpecialPathSegment(self.0.into_owned().into())
}
pub fn borrowed(&self) -> NonSpecialPathSegment<'_> {
NonSpecialPathSegment(Cow::Borrowed(&self.0))
}
}
impl<'a> From<Cow<'a, [u8]>> for NonSpecialPathSegment<'a> {
fn from(value: Cow<'a, [u8]>) -> Self {
let (_, value) = make_non_special_path_segment_bytes(value);
unsafe {
Self::new_unchecked(value)
}
}
}
impl<'a> From<PathSegment<'a>> for NonSpecialPathSegment<'a> {
fn from(value: PathSegment<'a>) -> Self {
match value {
PathSegment::File (x) => x.into(),
PathSegment::SpecialNotFile(x) => x.into(),
PathSegment::NonSpecial (x) => x,
}
}
}
impl<'a> From<SpecialNotFilePathSegment<'a>> for NonSpecialPathSegment<'a> {fn from(value: SpecialNotFilePathSegment<'a>) -> Self {Self(value.into_inner())}}
impl<'a> From<FilePathSegment <'a>> for NonSpecialPathSegment<'a> {fn from(value: FilePathSegment <'a>) -> Self {Self(value.into_inner())}}