use crate::prelude::*;
#[derive(Debug, Clone)]
pub struct SpecialNotFilePathSegment<'a>(Cow<'a, str>);
impl<'a> SpecialNotFilePathSegment<'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) -> SpecialNotFilePathSegment<'static> {
SpecialNotFilePathSegment(self.0.into_owned().into())
}
pub fn borrowed(&self) -> SpecialNotFilePathSegment<'_> {
SpecialNotFilePathSegment(Cow::Borrowed(&self.0))
}
}
impl<'a> From<Cow<'a, [u8]>> for SpecialNotFilePathSegment<'a> {
fn from(value: Cow<'a, [u8]>) -> Self {
let (_, value) = make_special_not_file_path_segment_bytes(value);
unsafe {
Self::new_unchecked(value)
}
}
}
impl<'a> From<PathSegment<'a>> for SpecialNotFilePathSegment<'a> {
fn from(value: PathSegment<'a>) -> Self {
match value {
PathSegment::File (x) => x.into(),
PathSegment::SpecialNotFile(x) => x,
PathSegment::NonSpecial (x) => x.into(),
}
}
}
impl<'a> From<FilePathSegment <'a>> for SpecialNotFilePathSegment<'a> {fn from(value: FilePathSegment <'a>) -> Self {Self( value.into_inner() )}}
impl<'a> From<NonSpecialPathSegment<'a>> for SpecialNotFilePathSegment<'a> {fn from(value: NonSpecialPathSegment<'a>) -> Self {Self(non_special_path_segment_to_special_not_file_path_segment(value.into_inner()).1)}}