pub enum Utf8TypedPath<'a> {
    Unix(&'a Utf8UnixPath),
    Windows(&'a Utf8WindowsPath),
}
Expand description

Represents a UTF-8 path with a known type that can be one of:

Variants§

§

Unix(&'a Utf8UnixPath)

§

Windows(&'a Utf8WindowsPath)

Implementations§

source§

impl<'a> Utf8TypedPath<'a>

source

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

Creates a new UTF* typed path 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 Utf8WindowsPath; otherwise, the slice will be represented as a Utf8UnixPath.

Examples
use typed_path::Utf8TypedPath;

assert!(Utf8TypedPath::new(r#"C:\some\path\to\file.txt"#).is_windows());
assert!(Utf8TypedPath::new(r#"\some\path\to\file.txt"#).is_windows());
assert!(Utf8TypedPath::new(r#"/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!(Utf8TypedPath::new(r#"some\path\to\file.txt"#).is_unix());
assert!(Utf8TypedPath::new("file.txt").is_unix());
assert!(Utf8TypedPath::new("").is_unix());
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 to_path_buf(&self) -> Utf8TypedPathBuf

Converts into a Utf8TypedPathBuf.

Trait Implementations§

source§

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

source§

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

Converts to this type from the input type.
source§

impl<'a> TryAsRef<Path> for Utf8TypedPath<'a>

source§

impl TryAsRef<Utf8Path<Utf8UnixEncoding>> for Utf8TypedPath<'_>

source§

impl TryAsRef<Utf8Path<Utf8WindowsEncoding>> for Utf8TypedPath<'_>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Utf8TypedPath<'a>

§

impl<'a> Send for Utf8TypedPath<'a>

§

impl<'a> Sync for Utf8TypedPath<'a>

§

impl<'a> Unpin for Utf8TypedPath<'a>

§

impl<'a> UnwindSafe for Utf8TypedPath<'a>

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.