use crate::prelude::*;
#[derive(Debug, Clone)]
pub enum Path<'a> {
Segmented(SegmentedPath<'a>),
Opaque (OpaquePath <'a>),
}
impl<'a> Path<'a> {
pub fn new<T: Into<FilePath<'a>> + Into<SpecialNotFilePath<'a>> + Into<NonSpecialPath<'a>> + Into<OpaquePath<'a>>>(value: T, r#type: PathType) -> Self {
match r#type {
PathType::Segmented(x) => Self::new_segmented(value, x),
PathType::Opaque => Self::new_opaque (value ),
}
}
pub fn new_segmented <T: Into<FilePath<'a>> + Into<SpecialNotFilePath<'a>> + Into<NonSpecialPath<'a>>>(value: T, r#type: SegmentedPathType) -> Self {SegmentedPath::new(value, r#type).into()}
pub fn new_file <T: Into<FilePath <'a>>>(value: T) -> Self {FilePath ::new(value).into()}
pub fn new_special_not_file<T: Into<SpecialNotFilePath<'a>>>(value: T) -> Self {SpecialNotFilePath::new(value).into()}
pub fn new_non_special <T: Into<NonSpecialPath <'a>>>(value: T) -> Self {NonSpecialPath ::new(value).into()}
pub fn new_opaque <T: Into<OpaquePath <'a>>>(value: T) -> Self {OpaquePath ::new(value).into()}
pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: T, r#type: PathType) -> Self {
match r#type {
PathType::Segmented(x) => unsafe {Self::new_segmented_unchecked(value, x)},
PathType::Opaque => unsafe {Self::new_opaque_unchecked (value )},
}
}
pub unsafe fn new_segmented_unchecked <T: Into<Cow<'a, str>>>(value: T, r#type: SegmentedPathType) -> Self {unsafe {SegmentedPath::new_unchecked(value, r#type)}.into()}
pub unsafe fn new_file_unchecked <T: Into<Cow<'a, str>>>(value: T) -> Self {unsafe {FilePath ::new_unchecked(value)}.into()}
pub unsafe fn new_special_not_file_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {unsafe {SpecialNotFilePath::new_unchecked(value)}.into()}
pub unsafe fn new_non_special_unchecked <T: Into<Cow<'a, str>>>(value: T) -> Self {unsafe {NonSpecialPath ::new_unchecked(value)}.into()}
pub unsafe fn new_opaque_unchecked <T: Into<Cow<'a, str>>>(value: T) -> Self {unsafe {OpaquePath ::new_unchecked(value)}.into()}
pub fn as_str(&self) -> &str {
match self {
Self::Segmented(x) => x.as_str(),
Self::Opaque (x) => x.as_str(),
}
}
pub fn r#type(&self) -> PathType {
match self {
Self::Segmented(x) => x.r#type().into(),
Self::Opaque (_) => PathType::Opaque,
}
}
pub fn is_segmented (&self) -> bool {matches!(self, Self::Segmented(_))}
pub fn is_file (&self) -> bool {matches!(self, Self::Segmented(SegmentedPath::File (_)))}
pub fn is_special_not_file(&self) -> bool {matches!(self, Self::Segmented(SegmentedPath::SpecialNotFile(_)))}
pub fn is_non_special (&self) -> bool {matches!(self, Self::Segmented(SegmentedPath::NonSpecial (_)))}
pub fn is_opaque (&self) -> bool {matches!(self, Self::Opaque (_))}
pub fn segmented(self) -> Option<SegmentedPath<'a>> {
match self {
Self::Segmented(x) => Some(x),
Self::Opaque (_) => None
}
}
pub fn file (self) -> Option<FilePath <'a>> {self.segmented()?.file ()}
pub fn special_not_file(self) -> Option<SpecialNotFilePath<'a>> {self.segmented()?.special_not_file()}
pub fn non_special (self) -> Option<NonSpecialPath <'a>> {self.segmented()?.non_special ()}
pub fn opaque(self) -> Option<OpaquePath<'a>> {
match self {
Self::Segmented(_) => None,
Self::Opaque (x) => Some(x),
}
}
pub fn into_inner(self) -> Cow<'a, str> {
match self {
Self::Segmented(x) => x.into_inner(),
Self::Opaque (x) => x.into_inner(),
}
}
pub fn into_owned(self) -> Path<'static> {
match self {
Self::Segmented(x) => x.into_owned().into(),
Self::Opaque (x) => x.into_owned().into(),
}
}
pub fn borrowed(&self) -> Path<'_> {
match self {
Self::Segmented(x) => x.borrowed().into() ,
Self::Opaque (x) => x.borrowed().into() ,
}
}
}
impl<'a> From<SegmentedPath <'a>> for Path<'a> {fn from(value: SegmentedPath <'a>) -> Self {Self::Segmented(value )}}
impl<'a> From<FilePath <'a>> for Path<'a> {fn from(value: FilePath <'a>) -> Self {Self::Segmented(value.into())}}
impl<'a> From<SpecialNotFilePath<'a>> for Path<'a> {fn from(value: SpecialNotFilePath<'a>) -> Self {Self::Segmented(value.into())}}
impl<'a> From<NonSpecialPath <'a>> for Path<'a> {fn from(value: NonSpecialPath <'a>) -> Self {Self::Segmented(value.into())}}
impl<'a> From<OpaquePath <'a>> for Path<'a> {fn from(value: OpaquePath <'a>) -> Self {Self::Opaque (value )}}