Struct normpath::BasePathBuf

source ·
pub struct BasePathBuf(_);
Expand description

An owned BasePath.

Implementations§

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());
}

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());
}

Returns the wrapped path as a platform string.

Returns the wrapped path.

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);
}

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);
}

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>§

Returns a reference to the wrapped path as a platform string.

Returns a reference to the wrapped path.

Equivalent to Path::canonicalize.

Equivalent to Path::components.

Equivalent to Path::ends_with.

Equivalent to Path::exists.

Equivalent to Path::extension.

Equivalent to Path::file_name.

Equivalent to Path::file_stem.

Equivalent to Path::has_root.

Equivalent to Path::is_absolute.

Equivalent to Path::is_dir.

Equivalent to Path::is_file.

Equivalent to Path::is_relative.

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"),
    );
}
Available on crate feature localization only.

Equivalent to PathExt::localize_name.

Equivalent to Path::metadata.

Equivalent to PathExt::normalize.

Available on Windows only.

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(),
    );
}

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(),
    );
}

Equivalent to Path::read_dir.

Equivalent to Path::read_link.

Equivalent to Path::starts_with.

Equivalent to Path::symlink_metadata.

Trait Implementations§

Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Escapes a string using the format described in the the module-level documentation, without the surrounding quotes. Read more
Quotes a string using the format described in the the module-level documentation. Read more
Serialize this value into the given Serde serializer. Read more
Returns a byte string that will be used to represent the instance.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.