Enum typed_path::Utf8TypedPathBuf
source · pub enum Utf8TypedPathBuf {
Unix(Utf8UnixPathBuf),
Windows(Utf8WindowsPathBuf),
}
Expand description
Represents a UTF-8 pathbuf with a known type that can be one of:
Variants§
Unix(Utf8UnixPathBuf)
Windows(Utf8WindowsPathBuf)
Implementations§
source§impl Utf8TypedPathBuf
impl Utf8TypedPathBuf
sourcepub fn is_windows(&self) -> bool
pub fn is_windows(&self) -> bool
Returns true if this path represents a Windows path.
sourcepub fn as_path(&self) -> Utf8TypedPath<'_>
pub fn as_path(&self) -> Utf8TypedPath<'_>
Converts into a Utf8TypedPath
.
Trait Implementations§
source§impl<'a> From<&'a str> for Utf8TypedPathBuf
impl<'a> From<&'a str> for Utf8TypedPathBuf
source§fn from(s: &'a str) -> Self
fn from(s: &'a str) -> Self
Creates a new UTF-8 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 Utf8WindowsPathBuf
; otherwise, the slice will be represented as a
Utf8UnixPathBuf
.
Examples
use typed_path::Utf8TypedPathBuf;
assert!(Utf8TypedPathBuf::from(r#"C:\some\path\to\file.txt"#).is_windows());
assert!(Utf8TypedPathBuf::from(r#"\some\path\to\file.txt"#).is_windows());
assert!(Utf8TypedPathBuf::from(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!(Utf8TypedPathBuf::from(r#"some\path\to\file.txt"#).is_unix());
assert!(Utf8TypedPathBuf::from("file.txt").is_unix());
assert!(Utf8TypedPathBuf::from("").is_unix());
source§impl From<String> for Utf8TypedPathBuf
impl From<String> for Utf8TypedPathBuf
source§impl TryFrom<Utf8TypedPathBuf> for PathBuf
impl TryFrom<Utf8TypedPathBuf> for PathBuf
§type Error = Utf8TypedPathBuf
type Error = Utf8TypedPathBuf
The type returned in the event of a conversion error.
source§impl TryFrom<Utf8TypedPathBuf> for Utf8UnixPathBuf
impl TryFrom<Utf8TypedPathBuf> for Utf8UnixPathBuf
§type Error = Utf8TypedPathBuf
type Error = Utf8TypedPathBuf
The type returned in the event of a conversion error.
source§impl TryFrom<Utf8TypedPathBuf> for Utf8WindowsPathBuf
impl TryFrom<Utf8TypedPathBuf> for Utf8WindowsPathBuf
§type Error = Utf8TypedPathBuf
type Error = Utf8TypedPathBuf
The type returned in the event of a conversion error.
Auto Trait Implementations§
impl RefUnwindSafe for Utf8TypedPathBuf
impl Send for Utf8TypedPathBuf
impl Sync for Utf8TypedPathBuf
impl Unpin for Utf8TypedPathBuf
impl UnwindSafe for Utf8TypedPathBuf
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