Struct normpath::BasePath [−][src]
A path that has a prefix on Windows.
Note that comparison traits such as PartialEq
will compare paths
literally instead of comparing components. The former is more efficient and
easier to use correctly.
Safety
This type should not be used for memory safety, but implementations can
panic if this path is missing a prefix on Windows. A safe new_unchecked
method might be added later that can safely create invalid base paths.
Although this type is annotated with #[repr(transparent)]
, the inner
representation is not stable. Transmuting between this type and any other
causes immediate undefined behavior.
Implementations
impl BasePath
[src]
pub fn new<'a, P>(path: P) -> Result<Cow<'a, Self>> where
P: Into<Cow<'a, Path>>,
[src]
P: Into<Cow<'a, Path>>,
Creates a new base path.
On Windows, if path
is missing a prefix, it will be joined to the
current directory.
Errors
Returns an error if reading the current directory fails.
Examples
use std::path::Path; use normpath::BasePath; if cfg!(windows) { let path = Path::new(r"X:\foo\bar"); assert_eq!(path, *BasePath::new(path)?); assert!(BasePath::new(Path::new(r"foo\bar")).is_ok()); }
pub fn try_new<P: ?Sized>(path: &P) -> Result<&Self, MissingPrefixError> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Creates a new base path.
Errors
On Windows, returns an error if path
is missing a prefix.
Examples
use std::path::Path; use normpath::BasePath; if cfg!(windows) { let path = r"X:\foo\bar"; assert_eq!(Path::new(path), BasePath::try_new(path)?); assert!(BasePath::try_new(r"foo\bar").is_err()); }
#[must_use]pub fn as_os_str(&self) -> &OsStr
[src]
Returns a reference to the wrapped path as a platform string.
#[must_use]pub fn as_path(&self) -> &Path
[src]
Returns a reference to the wrapped path.
pub fn canonicalize(&self) -> Result<BasePathBuf>
[src]
Equivalent to Path::canonicalize
.
#[must_use]pub fn components(&self) -> Components<'_>
[src]
Equivalent to Path::components
.
#[must_use]pub fn ends_with<P>(&self, child: P) -> bool where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Equivalent to Path::ends_with
.
#[must_use]pub fn exists(&self) -> bool
[src]
Equivalent to Path::exists
.
#[must_use]pub fn extension(&self) -> Option<&OsStr>
[src]
Equivalent to Path::extension
.
#[must_use]pub fn file_name(&self) -> Option<&OsStr>
[src]
Equivalent to Path::file_name
.
#[must_use]pub fn file_stem(&self) -> Option<&OsStr>
[src]
Equivalent to Path::file_stem
.
#[must_use]pub fn has_root(&self) -> bool
[src]
Equivalent to Path::has_root
.
#[must_use]pub fn is_absolute(&self) -> bool
[src]
Equivalent to Path::is_absolute
.
#[must_use]pub fn is_dir(&self) -> bool
[src]
Equivalent to Path::is_dir
.
#[must_use]pub fn is_file(&self) -> bool
[src]
Equivalent to Path::is_file
.
#[must_use]pub fn is_relative(&self) -> bool
[src]
Equivalent to Path::is_relative
.
pub fn join<P>(&self, path: P) -> BasePathBuf where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
An improved version of Path::join
that handles more edge cases.
For example, on Windows, leading .
and ..
components of path
will
be normalized if possible. If self
is a verbatim path, it would be
invalid to normalize them later.
You should still call normalize
before parent
to normalize some
additional components.
Examples
use std::path::Path; use normpath::BasePath; if cfg!(windows) { assert_eq!( Path::new(r"\\?\foo\baz\test.rs"), BasePath::try_new(r"\\?\foo\bar") .unwrap() .join("../baz/test.rs"), ); }
pub fn metadata(&self) -> Result<Metadata>
[src]
Equivalent to Path::metadata
.
pub fn normalize(&self) -> Result<BasePathBuf>
[src]
Equivalent to PathExt::normalize
.
pub fn normalize_virtually(&self) -> Result<BasePathBuf>
[src]
Equivalent to PathExt::normalize_virtually
.
pub fn parent(&self) -> Result<Option<&Self>, ParentError>
[src]
Returns this path without its last component.
Returns Ok(None)
if the last component is Component::RootDir
.
You should usually only call this method on normalized paths. They
will prevent an unexpected path from being returned due to symlinks,
and some .
and ..
components will be normalized.
Errors
Returns an error if the last component is not Component::Normal
or
Component::RootDir
. To ignore this error, use parent_unchecked
.
Examples
use std::path::Path; use normpath::BasePath; if cfg!(windows) { assert_eq!( Path::new(r"X:\foo"), BasePath::try_new(r"X:\foo\bar").unwrap().parent()?.unwrap(), ); }
#[must_use]pub fn parent_unchecked(&self) -> Option<&Self>
[src]
Equivalent to Path::parent
.
It is usually better to use parent
.
Examples
use std::path::Path; use normpath::BasePath; if cfg!(windows) { assert_eq!( Path::new(r"X:\foo"), BasePath::try_new(r"X:\foo\..") .unwrap() .parent_unchecked() .unwrap(), ); }
pub fn read_dir(&self) -> Result<ReadDir>
[src]
Equivalent to Path::read_dir
.
pub fn read_link(&self) -> Result<PathBuf>
[src]
Equivalent to Path::read_link
.
#[must_use]pub fn starts_with<P>(&self, base: P) -> bool where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Equivalent to Path::starts_with
.
pub fn symlink_metadata(&self) -> Result<Metadata>
[src]
Equivalent to Path::symlink_metadata
.
Trait Implementations
impl AsRef<BasePath> for BasePath
[src]
impl AsRef<BasePath> for BasePathBuf
[src]
impl AsRef<OsStr> for BasePath
[src]
impl AsRef<Path> for BasePath
[src]
impl Borrow<BasePath> for BasePathBuf
[src]
impl Debug for BasePath
[src]
impl Eq for BasePath
[src]
impl Hash for BasePath
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<&'_ BasePath> for BasePathBuf
[src]
fn eq(&self, other: &&BasePath) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<&'_ Path> for BasePath
[src]
impl PartialEq<BasePath> for BasePathBuf
[src]
fn eq(&self, other: &BasePath) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<BasePath> for BasePath
[src]
impl PartialEq<BasePathBuf> for BasePath
[src]
fn eq(&self, other: &BasePathBuf) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<BasePathBuf> for &BasePath
[src]
fn eq(&self, other: &BasePathBuf) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<Cow<'_, BasePath>> for BasePath
[src]
fn eq(&self, other: &Cow<'_, BasePath>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<Cow<'_, BasePath>> for &BasePath
[src]
fn eq(&self, other: &Cow<'_, BasePath>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<Cow<'_, Path>> for BasePath
[src]
fn eq(&self, other: &Cow<'_, Path>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<Cow<'_, Path>> for &BasePath
[src]
fn eq(&self, other: &Cow<'_, Path>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<Path> for &BasePath
[src]
impl PartialEq<Path> for BasePath
[src]
impl PartialEq<PathBuf> for BasePath
[src]
fn eq(&self, other: &PathBuf) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<PathBuf> for &BasePath
[src]
fn eq(&self, other: &PathBuf) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<&'_ BasePath> for BasePathBuf
[src]
fn partial_cmp(&self, other: &&BasePath) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<&'_ Path> for BasePath
[src]
fn partial_cmp(&self, other: &&Path) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<BasePath> for BasePathBuf
[src]
fn partial_cmp(&self, other: &BasePath) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<BasePath> for BasePath
[src]
fn partial_cmp(&self, other: &BasePath) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<BasePathBuf> for BasePath
[src]
fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<BasePathBuf> for &BasePath
[src]
fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Cow<'_, BasePath>> for BasePath
[src]
fn partial_cmp(&self, other: &Cow<'_, BasePath>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Cow<'_, BasePath>> for &BasePath
[src]
fn partial_cmp(&self, other: &Cow<'_, BasePath>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Cow<'_, Path>> for BasePath
[src]
fn partial_cmp(&self, other: &Cow<'_, Path>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Cow<'_, Path>> for &BasePath
[src]
fn partial_cmp(&self, other: &Cow<'_, Path>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Path> for &BasePath
[src]
fn partial_cmp(&self, other: &Path) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Path> for BasePath
[src]
fn partial_cmp(&self, other: &Path) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<PathBuf> for BasePath
[src]
fn partial_cmp(&self, other: &PathBuf) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<PathBuf> for &BasePath
[src]
fn partial_cmp(&self, other: &PathBuf) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for BasePath
[src]
impl StructuralPartialEq for BasePath
[src]
impl ToOwned for BasePath
[src]
type Owned = BasePathBuf
The resulting type after obtaining ownership.