Struct normpath::BasePathBuf[][src]

pub struct BasePathBuf(_);

An owned BasePath.

Implementations

impl BasePathBuf[src]

pub fn new<P>(path: P) -> Result<Self> where
    P: Into<PathBuf>, 
[src]

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]

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]

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]

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]

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]

This is supported on Windows only.

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.

Equivalent to Path::read_link.

#[must_use]pub fn starts_with<P>(&self, base: P) -> bool where
    P: AsRef<Path>, 
[src]

Equivalent to Path::starts_with.

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]

impl Debug for BasePathBuf[src]

impl Deref for BasePathBuf[src]

type Target = BasePath

The resulting type after dereferencing.

impl Eq for BasePathBuf[src]

impl Hash for BasePathBuf[src]

impl Ord for BasePathBuf[src]

impl PartialEq<&'_ BasePath> for BasePathBuf[src]

impl PartialEq<&'_ Path> for BasePathBuf[src]

impl PartialEq<BasePath> for BasePathBuf[src]

impl PartialEq<BasePathBuf> for BasePath[src]

impl PartialEq<BasePathBuf> for &BasePath[src]

impl PartialEq<BasePathBuf> for BasePathBuf[src]

impl PartialEq<Cow<'_, BasePath>> for BasePathBuf[src]

impl PartialEq<Cow<'_, Path>> for BasePathBuf[src]

impl PartialEq<Path> for BasePathBuf[src]

impl PartialEq<PathBuf> for BasePathBuf[src]

impl PartialOrd<&'_ BasePath> for BasePathBuf[src]

impl PartialOrd<&'_ Path> for BasePathBuf[src]

impl PartialOrd<BasePath> for BasePathBuf[src]

impl PartialOrd<BasePathBuf> for BasePath[src]

impl PartialOrd<BasePathBuf> for &BasePath[src]

impl PartialOrd<BasePathBuf> for BasePathBuf[src]

impl PartialOrd<Cow<'_, BasePath>> for BasePathBuf[src]

impl PartialOrd<Cow<'_, Path>> for BasePathBuf[src]

impl PartialOrd<Path> for BasePathBuf[src]

impl PartialOrd<PathBuf> for BasePathBuf[src]

impl StructuralEq for BasePathBuf[src]

impl StructuralPartialEq for BasePathBuf[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.