Struct normpath::BasePathBuf [−][src]
An owned BasePath
.
Implementations
impl BasePathBuf
[src]
pub fn new<P>(path: P) -> Result<Self> where
P: Into<PathBuf>,
[src]
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()); }
pub fn try_new<P>(path: P) -> Result<Self, MissingPrefixBufError> where
P: Into<PathBuf>,
[src]
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()); }
#[must_use]pub fn into_os_string(self) -> OsString
[src]
Returns the wrapped path as a platform string.
#[must_use]pub fn into_path_buf(self) -> PathBuf
[src]
Returns the wrapped path.
pub fn pop(&mut self) -> Result<bool, ParentError>
[src]
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); }
pub fn pop_unchecked(&mut self) -> bool
[src]
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); }
pub fn push<P>(&mut self, path: P) where
P: AsRef<Path>,
[src]
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>
#[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 BasePathBuf
[src]
impl AsRef<OsStr> for BasePathBuf
[src]
impl AsRef<Path> for BasePathBuf
[src]
impl Borrow<BasePath> for BasePathBuf
[src]
impl Clone for BasePathBuf
[src]
fn clone(&self) -> BasePathBuf
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for BasePathBuf
[src]
impl Deref for BasePathBuf
[src]
impl Eq for BasePathBuf
[src]
impl Hash for BasePathBuf
[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 Ord for BasePathBuf
[src]
fn cmp(&self, other: &BasePathBuf) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[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<&'_ Path> for BasePathBuf
[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<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<BasePathBuf> for BasePathBuf
[src]
fn eq(&self, other: &BasePathBuf) -> bool
[src]
fn ne(&self, other: &BasePathBuf) -> bool
[src]
impl PartialEq<Cow<'_, BasePath>> for BasePathBuf
[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 BasePathBuf
[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 BasePathBuf
[src]
impl PartialEq<PathBuf> for BasePathBuf
[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 BasePathBuf
[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<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<BasePathBuf> for BasePathBuf
[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 BasePathBuf
[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 BasePathBuf
[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 BasePathBuf
[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 BasePathBuf
[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 BasePathBuf
[src]
impl StructuralPartialEq for BasePathBuf
[src]
Auto Trait Implementations
impl RefUnwindSafe for BasePathBuf
impl Send for BasePathBuf
impl Sync for BasePathBuf
impl Unpin for BasePathBuf
impl UnwindSafe for BasePathBuf
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,