[][src]Crate relative_path

A platform-neutral relative path.

This provide types which are analogous to Path, and PathBuf found in stdlib, with the following characteristics:

  • The path separator is set to a fixed character (/), regardless of platform.
  • Relative paths cannot represent a path in the filesystem, without first specifying what they are relative to through to_path.

When two relative paths are compared to each other, their exact component makeup is taken into account:

use relative_path::RelativePath;

assert!(RelativePath::new("foo/bar/../baz") != RelativePath::new("foo/baz"));

Using platform-specific path separators to construct relative paths is not supported.

Path separators from other platforms are therefore treated as part of the component:

use relative_path::RelativePath;

assert_ne!(RelativePath::new("foo/bar"), RelativePath::new("foo\\bar"));

assert_eq!(1, RelativePath::new("foo\\bar").components().count());
assert_eq!(2, RelativePath::new("foo/bar").components().count());

To see if two logical paths are equivalent you can use normalize:

use relative_path::RelativePath;

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

Serde Support

This library includes serde support that can be enabled with the serde feature.

Structs

Components

Iterator over all the components in a relative path.

Display

Helper struct for printing relative paths.

FromPathError

An error raised when attempting to convert a path using RelativePathBuf::from_path.

Iter

An iterator over the Components of a RelativePath, as str slices.

RelativePath

A borrowed, immutable relative path.

RelativePathBuf

An owned, mutable relative path.

StripPrefixError

An error returned from RelativePath::strip_prefix if the prefix was not found.

Enums

Component
FromPathErrorKind