Struct relative_path::RelativePath [] [src]

pub struct RelativePath { /* fields omitted */ }

A borrowed, immutable relative path.

Methods

impl RelativePath
[src]

[src]

Directly wraps a string slice as a RelativePath slice.

[src]

Yields the underlying str slice.

Examples

use relative_path::RelativePath;

assert_eq!(RelativePath::new("foo.txt").as_str(), "foo.txt");

[src]

Returns an object that implements [Display].

Examples

use relative_path::RelativePath;

let path = RelativePath::new("tmp/foo.rs");

println!("{}", path.display());

[src]

Creates an owned RelativePathBuf with path adjoined to self.

Examples

use relative_path::RelativePath;

let path = RelativePath::new("foo/bar");
assert_eq!("foo/bar/baz", path.join("baz"));

[src]

Iterate over all components in this relative path.

Examples

use relative_path::{Component, RelativePath};

let path = RelativePath::new("foo/bar/baz");
let mut it = path.components();

assert_eq!(Some(Component::Normal("foo")), it.next());
assert_eq!(Some(Component::Normal("bar")), it.next());
assert_eq!(Some(Component::Normal("baz")), it.next());
assert_eq!(None, it.next());

[src]

Produces an iterator over the path's components viewed as str slices.

For more information about the particulars of how the path is separated into components, see components.

Examples

use relative_path::RelativePath;

let mut it = RelativePath::new("/tmp/foo.txt").iter();
assert_eq!(it.next(), Some("tmp"));
assert_eq!(it.next(), Some("foo.txt"));
assert_eq!(it.next(), None)

[src]

Convert to an owned RelativePathBuf.

[src]

Build an owned PathBuf relative to path for the current relative path.

Examples

use relative_path::RelativePath;
use std::path::Path;

let path = RelativePath::new("foo/bar").to_path(Path::new("."));
assert_eq!(Path::new("./foo/bar"), path);

[src]

Returns a relative path, without its final component if there is one.

Examples

use relative_path::RelativePath;

assert_eq!(Some(RelativePath::new("foo")), RelativePath::new("foo/bar").parent());
assert_eq!(None, RelativePath::new("foo").parent());
assert_eq!(None, RelativePath::new("").parent());

[src]

Returns the final component of the RelativePath, if there is one.

If the path is a normal file, this is the file name. If it's the path of a directory, this is the directory name.

Returns None If the path terminates in ...

Examples

use relative_path::RelativePath;

assert_eq!(Some("bin"), RelativePath::new("usr/bin/").file_name());
assert_eq!(Some("foo.txt"), RelativePath::new("tmp/foo.txt").file_name());
assert_eq!(Some("foo.txt"), RelativePath::new("tmp/foo.txt/").file_name());
assert_eq!(Some("foo.txt"), RelativePath::new("foo.txt/.").file_name());
assert_eq!(Some("foo.txt"), RelativePath::new("foo.txt/.//").file_name());
assert_eq!(None, RelativePath::new("foo.txt/..").file_name());
assert_eq!(None, RelativePath::new("/").file_name());

[src]

Returns a relative path that, when joined onto base, yields self.

Errors

If base is not a prefix of self (i.e. starts_with returns false), returns Err.

Examples

use relative_path::RelativePath;

let path = RelativePath::new("test/haha/foo.txt");

assert_eq!(path.strip_prefix("test"), Ok(RelativePath::new("haha/foo.txt")));
assert_eq!(path.strip_prefix("test").is_ok(), true);
assert_eq!(path.strip_prefix("haha").is_ok(), false);

[src]

Determines whether base is a prefix of self.

Only considers whole path components to match.

Examples

use relative_path::RelativePath;

let path = RelativePath::new("etc/passwd");

assert!(path.starts_with("etc"));

assert!(!path.starts_with("e"));

[src]

Determines whether child is a suffix of self.

Only considers whole path components to match.

Examples

use relative_path::RelativePath;

let path = RelativePath::new("etc/passwd");

assert!(path.ends_with("passwd"));

[src]

Creates an owned RelativePathBuf like self but with the given file name.

See RelativePathBuf::set_file_name for more details.

Examples

use relative_path::{RelativePath, RelativePathBuf};

let path = RelativePath::new("tmp/foo.txt");
assert_eq!(path.with_file_name("bar.txt"), RelativePathBuf::from("tmp/bar.txt"));

let path = RelativePath::new("tmp");
assert_eq!(path.with_file_name("var"), RelativePathBuf::from("var"));

[src]

Extracts the stem (non-extension) portion of self.file_name.

The stem is:

  • None, if there is no file name;
  • The entire file name if there is no embedded .;
  • The entire file name if the file name begins with . and has no other .s within;
  • Otherwise, the portion of the file name before the final .

Examples

use relative_path::RelativePath;

let path = RelativePath::new("foo.rs");

assert_eq!("foo", path.file_stem().unwrap());

[src]

Extracts the extension of self.file_name, if possible.

The extension is:

  • None, if there is no file name;
  • None, if there is no embedded .;
  • None, if the file name begins with . and has no other .s within;
  • Otherwise, the portion of the file name after the final .

Examples

use relative_path::RelativePath;

assert_eq!(Some("rs"), RelativePath::new("foo.rs").extension());
assert_eq!(None, RelativePath::new(".rs").extension());
assert_eq!(Some("rs"), RelativePath::new("foo.rs/.").extension());

[src]

Creates an owned RelativePathBuf like self but with the given extension.

See RelativePathBuf::set_extension for more details.

Examples

use relative_path::{RelativePath, RelativePathBuf};

let path = RelativePath::new("foo.rs");
assert_eq!(path.with_extension("txt"), RelativePathBuf::from("foo.txt"));

[src]

Build an owned RelativePathBuf, joined with the given path and normalized.

Examples

use relative_path::RelativePath;

assert_eq!(
    RelativePath::new("foo/baz.txt"),
    RelativePath::new("foo/bar").join_normalized("../baz.txt").as_relative_path()
);

assert_eq!(
    RelativePath::new("../foo/baz.txt"),
    RelativePath::new("../foo/bar").join_normalized("../baz.txt").as_relative_path()
);

[src]

Return an owned RelativePathBuf, with all non-normal components moved to the beginning of the path.

This permits for a normalized representation of different relative components.

Normalization is a destructive operation if the path references an actual filesystem path. An example of this is symlinks under unix, a path like foo/../bar might reference a different location other than ./bar.

Normalization is a logical operation that is only valid if the relative path is part of some context which doesn't have semantics that causes it to break, like symbolic links.

Examples

use relative_path::RelativePath;

assert_eq!(
    RelativePath::new("../foo/baz.txt"),
    RelativePath::new("../foo/./bar/../baz.txt").normalize().as_relative_path()
);

Trait Implementations

impl ToOwned for RelativePath
[src]

[src]

Creates owned data from borrowed data, usually by cloning. Read more

[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl Debug for RelativePath
[src]

[src]

Formats the value using the given formatter.

impl AsRef<RelativePath> for RelativePath
[src]

[src]

Performs the conversion.

impl PartialEq for RelativePath
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl Eq for RelativePath
[src]

impl PartialOrd for RelativePath
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for RelativePath
[src]

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

impl Hash for RelativePath
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<'a, 'b> PartialEq<RelativePathBuf> for RelativePath
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a, 'b> PartialOrd<RelativePathBuf> for RelativePath
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a, 'b> PartialEq<RelativePathBuf> for &'a RelativePath
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a, 'b> PartialOrd<RelativePathBuf> for &'a RelativePath
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a, 'b> PartialEq<Cow<'a, RelativePath>> for RelativePath
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a, 'b> PartialOrd<Cow<'a, RelativePath>> for RelativePath
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a, 'b> PartialEq<Cow<'a, RelativePath>> for &'b RelativePath
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a, 'b> PartialOrd<Cow<'a, RelativePath>> for &'b RelativePath
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a, 'b> PartialEq<str> for RelativePath
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a, 'b> PartialOrd<str> for RelativePath
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a, 'b> PartialEq<&'a str> for RelativePath
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a, 'b> PartialOrd<&'a str> for RelativePath
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a, 'b> PartialEq<String> for RelativePath
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a, 'b> PartialOrd<String> for RelativePath
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a, 'b> PartialEq<str> for &'a RelativePath
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a, 'b> PartialOrd<str> for &'a RelativePath
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a, 'b> PartialEq<String> for &'a RelativePath
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a, 'b> PartialOrd<String> for &'a RelativePath
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more