pub struct BasePathBuf(/* private fields */);
Implementations§
Source§impl BasePathBuf
impl BasePathBuf
Sourcepub fn new<P>(path: P) -> Result<Self>
pub fn new<P>(path: P) -> Result<Self>
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>
pub fn try_new<P>(path: P) -> Result<Self, MissingPrefixBufError>
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)
pub fn push<P>(&mut self, path: P)
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) -> bool
pub fn ends_with<P>(&self, child: P) -> bool
Equivalent to Path::ends_with
.
Sourcepub fn exists(&self) -> bool
pub fn exists(&self) -> bool
Equivalent to Path::exists
.
Sourcepub fn expand(&self) -> Result<Cow<'_, Self>>
pub fn expand(&self) -> Result<Cow<'_, Self>>
Equivalent to PathExt::expand
.
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 is_symlink(&self) -> bool
pub fn is_symlink(&self) -> bool
Equivalent to Path::is_symlink
.
Sourcepub fn join<P>(&self, path: P) -> BasePathBuf
pub fn join<P>(&self, path: P) -> BasePathBuf
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 localize_name(&self) -> Cow<'_, OsStr>
Available on crate feature localization
only.
pub fn localize_name(&self) -> Cow<'_, OsStr>
localization
only.Equivalent to PathExt::localize_name
.
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>
Available on Windows only.
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 shorten(&self) -> Result<Cow<'_, Self>>
pub fn shorten(&self) -> Result<Cow<'_, Self>>
Equivalent to PathExt::shorten
.
Sourcepub fn starts_with<P>(&self, base: P) -> bool
pub fn starts_with<P>(&self, base: P) -> bool
Equivalent to Path::starts_with
.
Sourcepub fn symlink_metadata(&self) -> Result<Metadata>
pub fn symlink_metadata(&self) -> Result<Metadata>
Equivalent to Path::symlink_metadata
.
Sourcepub fn try_exists(&self) -> Result<bool>
pub fn try_exists(&self) -> Result<bool>
Equivalent to Path::try_exists
.
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<'de> Deserialize<'de> for BasePathBuf
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for BasePathBuf
serde
only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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§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§impl PartialEq<BasePathBuf> for &Path
impl PartialEq<BasePathBuf> for &Path
Source§impl PartialEq<BasePathBuf> for BasePath
impl PartialEq<BasePathBuf> for BasePath
Source§impl PartialEq<BasePathBuf> for Path
impl PartialEq<BasePathBuf> for Path
Source§impl PartialEq<BasePathBuf> for PathBuf
impl PartialEq<BasePathBuf> for PathBuf
Source§impl PartialEq<Path> for BasePathBuf
impl PartialEq<Path> for BasePathBuf
Source§impl PartialEq<PathBuf> for BasePathBuf
impl PartialEq<PathBuf> for BasePathBuf
Source§impl PartialEq for BasePathBuf
impl PartialEq for BasePathBuf
Source§impl PartialOrd<&BasePath> for BasePathBuf
impl PartialOrd<&BasePath> for BasePathBuf
Source§impl PartialOrd<&Path> for BasePathBuf
impl PartialOrd<&Path> for BasePathBuf
Source§impl PartialOrd<BasePath> for BasePathBuf
impl PartialOrd<BasePath> for BasePathBuf
Source§impl PartialOrd<BasePathBuf> for &BasePath
impl PartialOrd<BasePathBuf> for &BasePath
Source§impl PartialOrd<BasePathBuf> for &Path
impl PartialOrd<BasePathBuf> for &Path
Source§impl PartialOrd<BasePathBuf> for BasePath
impl PartialOrd<BasePathBuf> for BasePath
Source§impl PartialOrd<BasePathBuf> for Cow<'_, BasePath>
impl PartialOrd<BasePathBuf> for Cow<'_, BasePath>
Source§impl PartialOrd<BasePathBuf> for Cow<'_, Path>
impl PartialOrd<BasePathBuf> for Cow<'_, Path>
Source§impl PartialOrd<BasePathBuf> for Path
impl PartialOrd<BasePathBuf> for Path
Source§impl PartialOrd<BasePathBuf> for PathBuf
impl PartialOrd<BasePathBuf> for PathBuf
Source§impl PartialOrd<Cow<'_, BasePath>> for BasePathBuf
impl PartialOrd<Cow<'_, BasePath>> for BasePathBuf
Source§impl PartialOrd<Cow<'_, Path>> for BasePathBuf
impl PartialOrd<Cow<'_, Path>> for BasePathBuf
Source§impl PartialOrd<Path> for BasePathBuf
impl PartialOrd<Path> for BasePathBuf
Source§impl PartialOrd<PathBuf> for BasePathBuf
impl PartialOrd<PathBuf> for BasePathBuf
Source§impl PartialOrd for BasePathBuf
impl PartialOrd for BasePathBuf
Source§impl Quote for BasePathBuf
Available on crate feature uniquote
only.
impl Quote for BasePathBuf
uniquote
only.Source§fn escape(&self, f: &mut Formatter<'_>) -> Result
fn escape(&self, f: &mut Formatter<'_>) -> Result
Source§fn quote(&self) -> Display<&Self>
fn quote(&self) -> Display<&Self>
Source§impl Serialize for BasePathBuf
Available on crate feature serde
only.
impl Serialize for BasePathBuf
serde
only.Source§impl ToBytes for BasePathBuf
Available on crate feature print_bytes
only.
impl ToBytes for BasePathBuf
print_bytes
only.