pub enum TypedPathBuf {
    Unix(UnixPathBuf),
    Windows(WindowsPathBuf),
}
Expand description

Represents a pathbuf with a known type that can be one of:

Variants§

Implementations§

source§

impl TypedPathBuf

source

pub fn is_unix(&self) -> bool

Returns true if this path represents a Unix path.

source

pub fn is_windows(&self) -> bool

Returns true if this path represents a Windows path.

source

pub fn as_path(&self) -> TypedPath<'_>

Converts into a TypedPath.

Trait Implementations§

source§

impl<'a> From<&'a [u8]> for TypedPathBuf

source§

fn from(s: &'a [u8]) -> Self

Creates a new typed pathbuf from a byte slice by determining if the path represents a Windows or Unix path. This is accomplished by first trying to parse as a Windows path. If the resulting path contains a prefix such as C: or begins with a \, it is assumed to be a WindowsPathBuf; otherwise, the slice will be represented as a UnixPathBuf.

Examples
use typed_path::TypedPathBuf;

assert!(TypedPathBuf::from(br#"C:\some\path\to\file.txt"#).is_windows());
assert!(TypedPathBuf::from(br#"\some\path\to\file.txt"#).is_windows());
assert!(TypedPathBuf::from(br#"/some/path/to/file.txt"#).is_unix());

// NOTE: If we don't start with a backslash, it's too difficult to
//       determine and we therefore just assume a Unix/POSIX path.
assert!(TypedPathBuf::from(br#"some\path\to\file.txt"#).is_unix());
assert!(TypedPathBuf::from(b"file.txt").is_unix());
assert!(TypedPathBuf::from(b"").is_unix());
source§

impl<'a, const N: usize> From<&'a [u8; N]> for TypedPathBuf

source§

fn from(s: &'a [u8; N]) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for TypedPathBuf

source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
source§

impl From<String> for TypedPathBuf

source§

fn from(s: String) -> Self

Converts to this type from the input type.
source§

impl From<Vec<u8>> for TypedPathBuf

source§

fn from(s: Vec<u8>) -> Self

Converts to this type from the input type.
source§

impl TryFrom<TypedPathBuf> for PathBuf

§

type Error = TypedPathBuf

The type returned in the event of a conversion error.
source§

fn try_from(path: TypedPathBuf) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TypedPathBuf> for UnixPathBuf

§

type Error = TypedPathBuf

The type returned in the event of a conversion error.
source§

fn try_from(path: TypedPathBuf) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TypedPathBuf> for WindowsPathBuf

§

type Error = TypedPathBuf

The type returned in the event of a conversion error.
source§

fn try_from(path: TypedPathBuf) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.