use crate::prelude::*;
mod get;
mod set;
mod remove;
#[derive(Debug, Clone)]
pub struct NonSpecialPath<'a>(Cow<'a, str>);
impl<'a> NonSpecialPath<'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 segments(&self) -> Option<NonSpecialPathSegments<'_>> {
Some(unsafe {NonSpecialPathSegments::new_unchecked(self.as_str().strip_prefix('/')?)})
}
pub fn into_inner(self) -> Cow<'a, str> {
self.0
}
pub fn into_owned(self) -> NonSpecialPath<'static> {
NonSpecialPath(self.0.into_owned().into())
}
pub fn borrowed(&self) -> NonSpecialPath<'_> {
NonSpecialPath(Cow::Borrowed(&self.0))
}
}
impl<'a> From<Cow<'a, [u8]>> for NonSpecialPath<'a> {
fn from(value: Cow<'a, [u8]>) -> Self {
let (_, value) = make_non_special_path_bytes(value);
unsafe {
Self::new_unchecked(value)
}
}
}
impl<'a> From<Path<'a>> for NonSpecialPath<'a> {
fn from(value: Path<'a>) -> Self {
match value {
Path::Segmented(x) => x.into(),
Path::Opaque (x) => x.into(),
}
}
}
impl<'a> From<SegmentedPath <'a>> for NonSpecialPath<'a> {fn from(value: SegmentedPath <'a>) -> Self {Self( value.into_inner() )}}
impl<'a> From<FilePath <'a>> for NonSpecialPath<'a> {fn from(value: FilePath <'a>) -> Self {Self( value.into_inner() )}}
impl<'a> From<SpecialNotFilePath<'a>> for NonSpecialPath<'a> {fn from(value: SpecialNotFilePath<'a>) -> Self {Self( value.into_inner() )}}
impl<'a> From<OpaquePath <'a>> for NonSpecialPath<'a> {fn from(value: OpaquePath <'a>) -> Self {Self(opaque_path_to_non_special_path(value.into_inner()).1)}}
impl From<PathSegments <'_>> for NonSpecialPath<'static> {fn from(value: PathSegments <'_>) -> Self {Self(resolve_non_special_path(value.into_inner().with_insert_str(0, "/")).1)}}
impl From<FilePathSegments <'_>> for NonSpecialPath<'static> {fn from(value: FilePathSegments <'_>) -> Self {Self(resolve_non_special_path(value.into_inner().with_insert_str(0, "/")).1)}}
impl From<SpecialNotFilePathSegments<'_>> for NonSpecialPath<'static> {fn from(value: SpecialNotFilePathSegments<'_>) -> Self {Self(resolve_non_special_path(value.into_inner().with_insert_str(0, "/")).1)}}
impl From<NonSpecialPathSegments <'_>> for NonSpecialPath<'static> {fn from(value: NonSpecialPathSegments <'_>) -> Self {Self(resolve_non_special_path(value.into_inner().with_insert_str(0, "/")).1)}}