Enum typed_path::Utf8TypedPath
source · 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>
impl<'a> Utf8TypedPath<'a>
sourcepub fn new(s: &'a str) -> Self
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());
sourcepub fn is_windows(&self) -> bool
pub fn is_windows(&self) -> bool
Returns true if this path represents a Windows path.
sourcepub fn to_path_buf(&self) -> Utf8TypedPathBuf
pub fn to_path_buf(&self) -> Utf8TypedPathBuf
Converts into a Utf8TypedPathBuf
.
Trait Implementations§
source§impl<'a> From<&'a str> for Utf8TypedPath<'a>
impl<'a> From<&'a str> for Utf8TypedPath<'a>
source§impl<'a> TryAsRef<Path> for Utf8TypedPath<'a>
impl<'a> TryAsRef<Path> for Utf8TypedPath<'a>
fn try_as_ref(&self) -> Option<&Path>
source§impl TryAsRef<Utf8Path<Utf8UnixEncoding>> for Utf8TypedPath<'_>
impl TryAsRef<Utf8Path<Utf8UnixEncoding>> for Utf8TypedPath<'_>
fn try_as_ref(&self) -> Option<&Utf8UnixPath>
source§impl TryAsRef<Utf8Path<Utf8WindowsEncoding>> for Utf8TypedPath<'_>
impl TryAsRef<Utf8Path<Utf8WindowsEncoding>> for Utf8TypedPath<'_>
fn try_as_ref(&self) -> Option<&Utf8WindowsPath>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more