Enum typed_path::TypedPath
source · pub enum TypedPath<'a> {
Unix(&'a UnixPath),
Windows(&'a WindowsPath),
}
Expand description
Represents a path with a known type that can be one of:
Variants§
Unix(&'a UnixPath)
Windows(&'a WindowsPath)
Implementations§
source§impl<'a> TypedPath<'a>
impl<'a> TypedPath<'a>
sourcepub fn new(s: &'a [u8]) -> Self
pub fn new(s: &'a [u8]) -> Self
Creates a new 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
WindowsPath
; otherwise, the slice will be represented as a UnixPath
.
Examples
use typed_path::TypedPath;
assert!(TypedPath::new(br#"C:\some\path\to\file.txt"#).is_windows());
assert!(TypedPath::new(br#"\some\path\to\file.txt"#).is_windows());
assert!(TypedPath::new(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!(TypedPath::new(br#"some\path\to\file.txt"#).is_unix());
assert!(TypedPath::new(b"file.txt").is_unix());
assert!(TypedPath::new(b"").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) -> TypedPathBuf
pub fn to_path_buf(&self) -> TypedPathBuf
Converts into a TypedPathBuf
.
Trait Implementations§
source§impl TryAsRef<Path<UnixEncoding>> for TypedPath<'_>
impl TryAsRef<Path<UnixEncoding>> for TypedPath<'_>
fn try_as_ref(&self) -> Option<&UnixPath>
source§impl TryAsRef<Path<WindowsEncoding>> for TypedPath<'_>
impl TryAsRef<Path<WindowsEncoding>> for TypedPath<'_>
fn try_as_ref(&self) -> Option<&WindowsPath>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for TypedPath<'a>
impl<'a> Send for TypedPath<'a>
impl<'a> Sync for TypedPath<'a>
impl<'a> Unpin for TypedPath<'a>
impl<'a> UnwindSafe for TypedPath<'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