Struct normpath::BasePathBuf
source · pub struct BasePathBuf(/* private fields */);Implementations§
source§impl BasePathBuf
impl BasePathBuf
sourcepub fn new<P>(path: P) -> Result<Self>where
P: Into<PathBuf>,
pub fn new<P>(path: P) -> Result<Self>where P: Into<PathBuf>,
Equivalent to BasePath::new but returns an owned path.
Examples
use std::path::Path;
use normpath::BasePathBuf;
if cfg!(windows) {
let path = r"X:\foo\bar";
assert_eq!(Path::new(path), BasePathBuf::new(path)?);
assert!(BasePathBuf::new(r"foo\bar").is_ok());
}sourcepub fn try_new<P>(path: P) -> Result<Self, MissingPrefixBufError>where
P: Into<PathBuf>,
pub fn try_new<P>(path: P) -> Result<Self, MissingPrefixBufError>where P: Into<PathBuf>,
Equivalent to BasePath::try_new but returns an owned path.
Examples
use std::path::Path;
use normpath::BasePathBuf;
if cfg!(windows) {
let path = r"X:\foo\bar";
assert_eq!(Path::new(path), BasePathBuf::try_new(path)?);
assert!(BasePathBuf::try_new(r"foo\bar").is_err());
}sourcepub fn into_os_string(self) -> OsString
pub fn into_os_string(self) -> OsString
Returns the wrapped path as a platform string.
sourcepub fn into_path_buf(self) -> PathBuf
pub fn into_path_buf(self) -> PathBuf
Returns the wrapped path.
sourcepub fn pop(&mut self) -> Result<bool, ParentError>
pub fn pop(&mut self) -> Result<bool, ParentError>
Equivalent to BasePath::parent but modifies self in place.
Returns Ok(false) when BasePath::parent returns Ok(None).
Examples
use std::path::Path;
use normpath::BasePathBuf;
if cfg!(windows) {
let mut path = BasePathBuf::try_new(r"X:\foo\bar").unwrap();
assert!(path.pop()?);
assert_eq!(Path::new(r"X:\foo"), path);
}sourcepub fn pop_unchecked(&mut self) -> bool
pub fn pop_unchecked(&mut self) -> bool
Equivalent to PathBuf::pop.
It is usually better to use pop.
Examples
use std::path::Path;
use normpath::BasePathBuf;
if cfg!(windows) {
let mut path = BasePathBuf::try_new(r"X:\foo\..").unwrap();
assert!(path.pop_unchecked());
assert_eq!(Path::new(r"X:\foo"), path);
}sourcepub fn push<P>(&mut self, path: P)where
P: AsRef<Path>,
pub fn push<P>(&mut self, path: P)where P: AsRef<Path>,
Equivalent to BasePath::join but modifies self in place.
Examples
use std::path::Path;
use normpath::BasePathBuf;
if cfg!(windows) {
let mut path = BasePathBuf::try_new(r"\\?\foo\bar").unwrap();
path.push("../baz/test.rs");
assert_eq!(Path::new(r"\\?\foo\baz\test.rs"), path);
}Methods from Deref<Target = BasePath>§
sourcepub fn as_os_str(&self) -> &OsStr
pub fn as_os_str(&self) -> &OsStr
Returns a reference to the wrapped path as a platform string.
sourcepub fn canonicalize(&self) -> Result<BasePathBuf>
pub fn canonicalize(&self) -> Result<BasePathBuf>
Equivalent to Path::canonicalize.
sourcepub fn components(&self) -> Components<'_>
pub fn components(&self) -> Components<'_>
Equivalent to Path::components.
sourcepub fn ends_with<P>(&self, child: P) -> boolwhere
P: AsRef<Path>,
pub fn ends_with<P>(&self, child: P) -> boolwhere P: AsRef<Path>,
Equivalent to Path::ends_with.
sourcepub fn exists(&self) -> bool
pub fn exists(&self) -> bool
Equivalent to Path::exists.
sourcepub fn extension(&self) -> Option<&OsStr>
pub fn extension(&self) -> Option<&OsStr>
Equivalent to Path::extension.
sourcepub fn file_name(&self) -> Option<&OsStr>
pub fn file_name(&self) -> Option<&OsStr>
Equivalent to Path::file_name.
sourcepub fn file_stem(&self) -> Option<&OsStr>
pub fn file_stem(&self) -> Option<&OsStr>
Equivalent to Path::file_stem.
sourcepub fn has_root(&self) -> bool
pub fn has_root(&self) -> bool
Equivalent to Path::has_root.
sourcepub fn is_absolute(&self) -> bool
pub fn is_absolute(&self) -> bool
Equivalent to Path::is_absolute.
sourcepub fn is_dir(&self) -> bool
pub fn is_dir(&self) -> bool
Equivalent to Path::is_dir.
sourcepub fn is_file(&self) -> bool
pub fn is_file(&self) -> bool
Equivalent to Path::is_file.
sourcepub fn is_relative(&self) -> bool
pub fn is_relative(&self) -> bool
Equivalent to Path::is_relative.
sourcepub fn join<P>(&self, path: P) -> BasePathBufwhere
P: AsRef<Path>,
pub fn join<P>(&self, path: P) -> BasePathBufwhere 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"),
);
}sourcepub fn metadata(&self) -> Result<Metadata>
pub fn metadata(&self) -> Result<Metadata>
Equivalent to Path::metadata.
sourcepub fn normalize(&self) -> Result<BasePathBuf>
pub fn normalize(&self) -> Result<BasePathBuf>
Equivalent to PathExt::normalize.
sourcepub fn normalize_virtually(&self) -> Result<BasePathBuf>
pub fn normalize_virtually(&self) -> Result<BasePathBuf>
Equivalent to PathExt::normalize_virtually.
sourcepub fn parent(&self) -> Result<Option<&Self>, ParentError>
pub fn parent(&self) -> Result<Option<&Self>, ParentError>
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(),
);
}sourcepub fn parent_unchecked(&self) -> Option<&Self>
pub fn parent_unchecked(&self) -> Option<&Self>
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(),
);
}sourcepub fn read_dir(&self) -> Result<ReadDir>
pub fn read_dir(&self) -> Result<ReadDir>
Equivalent to Path::read_dir.
sourcepub fn read_link(&self) -> Result<PathBuf>
pub fn read_link(&self) -> Result<PathBuf>
Equivalent to Path::read_link.
sourcepub fn starts_with<P>(&self, base: P) -> boolwhere
P: AsRef<Path>,
pub fn starts_with<P>(&self, base: P) -> boolwhere P: AsRef<Path>,
Equivalent to Path::starts_with.
sourcepub fn symlink_metadata(&self) -> Result<Metadata>
pub fn symlink_metadata(&self) -> Result<Metadata>
Equivalent to Path::symlink_metadata.
Trait Implementations§
source§impl AsRef<BasePath> for BasePathBuf
impl AsRef<BasePath> for BasePathBuf
source§impl AsRef<OsStr> for BasePathBuf
impl AsRef<OsStr> for BasePathBuf
source§impl AsRef<Path> for BasePathBuf
impl AsRef<Path> for BasePathBuf
source§impl Borrow<BasePath> for BasePathBuf
impl Borrow<BasePath> for BasePathBuf
source§impl Clone for BasePathBuf
impl Clone for BasePathBuf
source§fn clone(&self) -> BasePathBuf
fn clone(&self) -> BasePathBuf
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for BasePathBuf
impl Debug for BasePathBuf
source§impl Deref for BasePathBuf
impl Deref for BasePathBuf
source§impl From<BasePathBuf> for Cow<'_, BasePath>
impl From<BasePathBuf> for Cow<'_, BasePath>
source§fn from(value: BasePathBuf) -> Self
fn from(value: BasePathBuf) -> Self
source§impl From<BasePathBuf> for OsString
impl From<BasePathBuf> for OsString
source§fn from(value: BasePathBuf) -> Self
fn from(value: BasePathBuf) -> Self
source§impl From<BasePathBuf> for PathBuf
impl From<BasePathBuf> for PathBuf
source§fn from(value: BasePathBuf) -> Self
fn from(value: BasePathBuf) -> Self
source§impl Hash for BasePathBuf
impl Hash for BasePathBuf
source§impl Ord for BasePathBuf
impl Ord for BasePathBuf
source§fn cmp(&self, other: &BasePathBuf) -> Ordering
fn cmp(&self, other: &BasePathBuf) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<&BasePath> for BasePathBuf
impl PartialEq<&BasePath> for BasePathBuf
source§impl PartialEq<&Path> for BasePathBuf
impl PartialEq<&Path> for BasePathBuf
source§impl PartialEq<BasePath> for BasePathBuf
impl PartialEq<BasePath> for BasePathBuf
source§impl PartialEq<BasePathBuf> for &BasePath
impl PartialEq<BasePathBuf> for &BasePath
source§fn eq(&self, other: &BasePathBuf) -> bool
fn eq(&self, other: &BasePathBuf) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<BasePathBuf> for &Path
impl PartialEq<BasePathBuf> for &Path
source§fn eq(&self, other: &BasePathBuf) -> bool
fn eq(&self, other: &BasePathBuf) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<BasePathBuf> for BasePath
impl PartialEq<BasePathBuf> for BasePath
source§fn eq(&self, other: &BasePathBuf) -> bool
fn eq(&self, other: &BasePathBuf) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<BasePathBuf> for BasePathBuf
impl PartialEq<BasePathBuf> for BasePathBuf
source§fn eq(&self, other: &BasePathBuf) -> bool
fn eq(&self, other: &BasePathBuf) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<BasePathBuf> for Cow<'_, BasePath>
impl PartialEq<BasePathBuf> for Cow<'_, BasePath>
source§fn eq(&self, other: &BasePathBuf) -> bool
fn eq(&self, other: &BasePathBuf) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<BasePathBuf> for Cow<'_, Path>
impl PartialEq<BasePathBuf> for Cow<'_, Path>
source§fn eq(&self, other: &BasePathBuf) -> bool
fn eq(&self, other: &BasePathBuf) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<BasePathBuf> for Path
impl PartialEq<BasePathBuf> for Path
source§fn eq(&self, other: &BasePathBuf) -> bool
fn eq(&self, other: &BasePathBuf) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<BasePathBuf> for PathBuf
impl PartialEq<BasePathBuf> for PathBuf
source§fn eq(&self, other: &BasePathBuf) -> bool
fn eq(&self, other: &BasePathBuf) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<Cow<'_, BasePath>> for BasePathBuf
impl PartialEq<Cow<'_, BasePath>> for BasePathBuf
source§impl PartialEq<Cow<'_, Path>> for BasePathBuf
impl PartialEq<Cow<'_, Path>> for BasePathBuf
source§impl PartialEq<Path> for BasePathBuf
impl PartialEq<Path> for BasePathBuf
source§impl PartialEq<PathBuf> for BasePathBuf
impl PartialEq<PathBuf> for BasePathBuf
source§impl PartialOrd<&BasePath> for BasePathBuf
impl PartialOrd<&BasePath> for BasePathBuf
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<&Path> for BasePathBuf
impl PartialOrd<&Path> for BasePathBuf
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<BasePath> for BasePathBuf
impl PartialOrd<BasePath> for BasePathBuf
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<BasePathBuf> for &BasePath
impl PartialOrd<BasePathBuf> for &BasePath
source§fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<BasePathBuf> for &Path
impl PartialOrd<BasePathBuf> for &Path
source§fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<BasePathBuf> for BasePath
impl PartialOrd<BasePathBuf> for BasePath
source§fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<BasePathBuf> for BasePathBuf
impl PartialOrd<BasePathBuf> for BasePathBuf
source§fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<BasePathBuf> for Cow<'_, BasePath>
impl PartialOrd<BasePathBuf> for Cow<'_, BasePath>
source§fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<BasePathBuf> for Cow<'_, Path>
impl PartialOrd<BasePathBuf> for Cow<'_, Path>
source§fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<BasePathBuf> for Path
impl PartialOrd<BasePathBuf> for Path
source§fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<BasePathBuf> for PathBuf
impl PartialOrd<BasePathBuf> for PathBuf
source§fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
fn partial_cmp(&self, other: &BasePathBuf) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<Cow<'_, BasePath>> for BasePathBuf
impl PartialOrd<Cow<'_, BasePath>> for BasePathBuf
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<Cow<'_, Path>> for BasePathBuf
impl PartialOrd<Cow<'_, Path>> for BasePathBuf
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<Path> for BasePathBuf
impl PartialOrd<Path> for BasePathBuf
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<PathBuf> for BasePathBuf
impl PartialOrd<PathBuf> for BasePathBuf
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more