Enum typed_path::TypedPathBuf
source · pub enum TypedPathBuf {
Unix(UnixPathBuf),
Windows(WindowsPathBuf),
}
Expand description
Represents a pathbuf with a known type that can be one of:
Variants§
Unix(UnixPathBuf)
Windows(WindowsPathBuf)
Implementations§
Trait Implementations§
source§impl<'a> From<&'a [u8]> for TypedPathBuf
impl<'a> From<&'a [u8]> for TypedPathBuf
source§fn from(s: &'a [u8]) -> Self
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> From<&'a str> for TypedPathBuf
impl<'a> From<&'a str> for TypedPathBuf
source§impl From<String> for TypedPathBuf
impl From<String> for TypedPathBuf
source§impl TryFrom<TypedPathBuf> for PathBuf
impl TryFrom<TypedPathBuf> for PathBuf
§type Error = TypedPathBuf
type Error = TypedPathBuf
The type returned in the event of a conversion error.
source§impl TryFrom<TypedPathBuf> for UnixPathBuf
impl TryFrom<TypedPathBuf> for UnixPathBuf
§type Error = TypedPathBuf
type Error = TypedPathBuf
The type returned in the event of a conversion error.
source§impl TryFrom<TypedPathBuf> for WindowsPathBuf
impl TryFrom<TypedPathBuf> for WindowsPathBuf
§type Error = TypedPathBuf
type Error = TypedPathBuf
The type returned in the event of a conversion error.
Auto Trait Implementations§
impl RefUnwindSafe for TypedPathBuf
impl Send for TypedPathBuf
impl Sync for TypedPathBuf
impl Unpin for TypedPathBuf
impl UnwindSafe for TypedPathBuf
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