Struct Path

Source
pub struct Path<T>
where T: Encoding,
{ /* private fields */ }
Expand description

A slice of a path (akin to str).

This type supports a number of operations for inspecting a path, including breaking the path into its components (separated by / on Unix and by either / or \ on Windows), extracting the file name, determining whether the path is absolute, and so on.

This is an unsized type, meaning that it must always be used behind a pointer like & or Box. For an owned version of this type, see PathBuf.

§Examples

use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding,
//       but all encodings work on all operating systems, providing the
//       ability to parse and operate on paths independently of the
//       compiled platform
let path = Path::<UnixEncoding>::new("./foo/bar.txt");

let parent = path.parent();
assert_eq!(parent, Some(Path::new("./foo")));

let file_stem = path.file_stem();
assert_eq!(file_stem, Some(b"bar".as_slice()));

let extension = path.extension();
assert_eq!(extension, Some(b"txt".as_slice()));

In addition to explicitly using Encodings, you can also leverage aliases available from the crate to work with paths:

use typed_path::{UnixPath, WindowsPath};

// Same as Path<UnixEncoding>
let path = UnixPath::new("/foo/bar.txt");

// Same as Path<WindowsEncoding>
let path = WindowsPath::new(r"C:\foo\bar.txt");

To mirror the design of Rust’s standard library, you can access the path associated with the compiled rust platform using NativePath, which itself is an alias to one of the other choices:

use typed_path::NativePath;

// On Unix, this would be UnixPath aka Path<UnixEncoding>
// On Windows, this would be WindowsPath aka Path<WindowsEncoding>
let path = NativePath::new("/foo/bar.txt");

Implementations§

Source§

impl<T> Path<T>
where T: Encoding,

Source

pub fn new<S: AsRef<[u8]> + ?Sized>(s: &S) -> &Self

Directly wraps a byte slice as a Path slice.

This is a cost-free conversion.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
Path::<UnixEncoding>::new("foo.txt");

You can create Paths from Strings, or even other Paths:

use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let string = String::from("foo.txt");
let from_string = Path::<UnixEncoding>::new(&string);
let from_path = Path::new(&from_string);
assert_eq!(from_string, from_path);

There are also handy aliases to the Path with Encoding:

use typed_path::UnixPath;

let string = String::from("foo.txt");
let from_string = UnixPath::new(&string);
let from_path = UnixPath::new(&from_string);
assert_eq!(from_string, from_path);
Examples found in repository?
examples/unix.rs (line 4)
3fn main() {
4    let path = UnixPath::new(r"/path/to/file.txt");
5
6    for component in path.components() {
7        println!("{}", String::from_utf8_lossy(component.as_bytes()));
8    }
9}
More examples
Hide additional examples
examples/windows.rs (line 4)
3fn main() {
4    let path = WindowsPath::new(r"C:\path\to\file.txt");
5
6    for component in path.components() {
7        println!("{}", String::from_utf8_lossy(component.as_bytes()));
8    }
9}
examples/platform.rs (line 5)
3fn main() {
4    // You can create the path like normal, but it is a distinct encoding from Unix/Windows
5    let path = PlatformPath::new("some/path");
6
7    // The path will still behave like normal and even report its underlying encoding
8    assert_eq!(path.has_unix_encoding(), cfg!(unix));
9    assert_eq!(path.has_windows_encoding(), cfg!(windows));
10
11    // It can still be converted into specific platform paths
12    let _ = path.with_unix_encoding();
13    let _ = path.with_windows_encoding();
14}
Source

pub fn as_bytes(&self) -> &[u8]

Yields the underlying [[u8]] slice.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let bytes = Path::<UnixEncoding>::new("foo.txt").as_bytes();
assert_eq!(bytes, b"foo.txt");
Source

pub fn to_str(&self) -> Option<&str>

Yields a &str slice if the Path is valid unicode.

This conversion may entail doing a check for UTF-8 validity. Note that validation is performed because non-UTF-8 strings are perfectly valid for some OS.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("foo.txt");
assert_eq!(path.to_str(), Some("foo.txt"));
Source

pub fn to_string_lossy(&self) -> Cow<'_, str>

Converts a Path to a Cow<str>.

Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.

§Examples

Calling to_string_lossy on a Path with valid unicode:

use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("foo.txt");
assert_eq!(path.to_string_lossy(), "foo.txt");

Had path contained invalid unicode, the to_string_lossy call might have returned "fo�.txt".

Source

pub fn to_path_buf(&self) -> PathBuf<T>

Converts a Path to an owned PathBuf.

§Examples
use typed_path::{Path, PathBuf, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path_buf = Path::<UnixEncoding>::new("foo.txt").to_path_buf();
assert_eq!(path_buf, PathBuf::from("foo.txt"));
Source

pub fn is_absolute(&self) -> bool

Returns true if the Path is absolute, i.e., if it is independent of the current directory.

  • On Unix (UnixPath]), a path is absolute if it starts with the root, so is_absolute and has_root are equivalent.

  • On Windows (WindowsPath), a path is absolute if it has a prefix and starts with the root: c:\windows is absolute, while c:temp and \temp are not.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
assert!(!Path::<UnixEncoding>::new("foo.txt").is_absolute());
Source

pub fn is_relative(&self) -> bool

Returns true if the Path is relative, i.e., not absolute.

See is_absolute’s documentation for more details.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
assert!(Path::<UnixEncoding>::new("foo.txt").is_relative());
Source

pub fn is_valid(&self) -> bool

Returns true if the path is valid, meaning that all of its components are valid.

See Component::is_valid’s documentation for more details.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
assert!(Path::<UnixEncoding>::new("foo.txt").is_valid());
assert!(!Path::<UnixEncoding>::new("foo\0.txt").is_valid());
Source

pub fn has_root(&self) -> bool

Returns true if the Path has a root.

  • On Unix (UnixPath), a path has a root if it begins with /.

  • On Windows (WindowsPath), a path has a root if it:

    • has no prefix and begins with a separator, e.g., \windows
    • has a prefix followed by a separator, e.g., c:\windows but not c:windows
    • has any non-disk prefix, e.g., \\server\share
§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
assert!(Path::<UnixEncoding>::new("/etc/passwd").has_root());
Source

pub fn parent(&self) -> Option<&Self>

Returns the Path without its final component, if there is one.

Returns None if the path terminates in a root or prefix.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("/foo/bar");
let parent = path.parent().unwrap();
assert_eq!(parent, Path::new("/foo"));

let grand_parent = parent.parent().unwrap();
assert_eq!(grand_parent, Path::new("/"));
assert_eq!(grand_parent.parent(), None);
Source

pub fn ancestors(&self) -> Ancestors<'_, T>

Produces an iterator over Path and its ancestors.

The iterator will yield the Path that is returned if the parent method is used zero or more times. That means, the iterator will yield &self, &self.parent().unwrap(), &self.parent().unwrap().parent().unwrap() and so on. If the parent method returns None, the iterator will do likewise. The iterator will always yield at least one value, namely &self.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let mut ancestors = Path::<UnixEncoding>::new("/foo/bar").ancestors();
assert_eq!(ancestors.next(), Some(Path::new("/foo/bar")));
assert_eq!(ancestors.next(), Some(Path::new("/foo")));
assert_eq!(ancestors.next(), Some(Path::new("/")));
assert_eq!(ancestors.next(), None);

// NOTE: A path cannot be created on its own without a defined encoding
let mut ancestors = Path::<UnixEncoding>::new("../foo/bar").ancestors();
assert_eq!(ancestors.next(), Some(Path::new("../foo/bar")));
assert_eq!(ancestors.next(), Some(Path::new("../foo")));
assert_eq!(ancestors.next(), Some(Path::new("..")));
assert_eq!(ancestors.next(), Some(Path::new("")));
assert_eq!(ancestors.next(), None);
Source

pub fn file_name(&self) -> Option<&[u8]>

Returns the final component of the Path, 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 typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
assert_eq!(Some(b"bin".as_slice()), Path::<UnixEncoding>::new("/usr/bin/").file_name());
assert_eq!(Some(b"foo.txt".as_slice()), Path::<UnixEncoding>::new("tmp/foo.txt").file_name());
assert_eq!(Some(b"foo.txt".as_slice()), Path::<UnixEncoding>::new("foo.txt/.").file_name());
assert_eq!(Some(b"foo.txt".as_slice()), Path::<UnixEncoding>::new("foo.txt/.//").file_name());
assert_eq!(None, Path::<UnixEncoding>::new("foo.txt/..").file_name());
assert_eq!(None, Path::<UnixEncoding>::new("/").file_name());
Source

pub fn strip_prefix<P>(&self, base: P) -> Result<&Path<T>, StripPrefixError>
where P: AsRef<Path<T>>,

Returns a 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 typed_path::{Path, PathBuf, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("/test/haha/foo.txt");

assert_eq!(path.strip_prefix("/"), Ok(Path::new("test/haha/foo.txt")));
assert_eq!(path.strip_prefix("/test"), Ok(Path::new("haha/foo.txt")));
assert_eq!(path.strip_prefix("/test/"), Ok(Path::new("haha/foo.txt")));
assert_eq!(path.strip_prefix("/test/haha/foo.txt"), Ok(Path::new("")));
assert_eq!(path.strip_prefix("/test/haha/foo.txt/"), Ok(Path::new("")));

assert!(path.strip_prefix("test").is_err());
assert!(path.strip_prefix("/haha").is_err());

let prefix = PathBuf::<UnixEncoding>::from("/test/");
assert_eq!(path.strip_prefix(prefix), Ok(Path::new("haha/foo.txt")));
Source

pub fn starts_with<P>(&self, base: P) -> bool
where P: AsRef<Path<T>>,

Determines whether base is a prefix of self.

Only considers whole path components to match.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("/etc/passwd");

assert!(path.starts_with("/etc"));
assert!(path.starts_with("/etc/"));
assert!(path.starts_with("/etc/passwd"));
assert!(path.starts_with("/etc/passwd/")); // extra slash is okay
assert!(path.starts_with("/etc/passwd///")); // multiple extra slashes are okay

assert!(!path.starts_with("/e"));
assert!(!path.starts_with("/etc/passwd.txt"));

assert!(!Path::<UnixEncoding>::new("/etc/foo.rs").starts_with("/etc/foo"));
Source

pub fn ends_with<P>(&self, child: P) -> bool
where P: AsRef<Path<T>>,

Determines whether child is a suffix of self.

Only considers whole path components to match.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("/etc/resolv.conf");

assert!(path.ends_with("resolv.conf"));
assert!(path.ends_with("etc/resolv.conf"));
assert!(path.ends_with("/etc/resolv.conf"));

assert!(!path.ends_with("/resolv.conf"));
assert!(!path.ends_with("conf")); // use .extension() instead
Source

pub fn file_stem(&self) -> Option<&[u8]>

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 typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
assert_eq!(b"foo", Path::<UnixEncoding>::new("foo.rs").file_stem().unwrap());
assert_eq!(b"foo.tar", Path::<UnixEncoding>::new("foo.tar.gz").file_stem().unwrap());
Source

pub fn extension(&self) -> Option<&[u8]>

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 typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
assert_eq!(b"rs", Path::<UnixEncoding>::new("foo.rs").extension().unwrap());
assert_eq!(b"gz", Path::<UnixEncoding>::new("foo.tar.gz").extension().unwrap());
Source

pub fn normalize(&self) -> PathBuf<T>

Returns an owned PathBuf by resolving .. and . segments.

When multiple, sequential path segment separation characters are found (e.g. / for Unix and either \ or / on Windows), they are replaced by a single instance of the platform-specific path segment separator (/ on Unix and \ on Windows).

§Examples
use typed_path::{Path, PathBuf, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
assert_eq!(
    Path::<UnixEncoding>::new("foo/bar//baz/./asdf/quux/..").normalize(),
    PathBuf::from("foo/bar/baz/asdf"),
);

When starting with a root directory, any .. segment whose parent is the root directory will be filtered out:

use typed_path::{Path, PathBuf, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
assert_eq!(
    Path::<UnixEncoding>::new("/../foo").normalize(),
    PathBuf::from("/foo"),
);

If any .. is left unresolved as the path is relative and no parent is found, it is discarded:

use typed_path::{Path, PathBuf, UnixEncoding, WindowsEncoding};

assert_eq!(
    Path::<UnixEncoding>::new("../foo/..").normalize(),
    PathBuf::from(""),
);

// Windows prefixes also count this way, but the prefix remains
assert_eq!(
    Path::<WindowsEncoding>::new(r"C:..\foo\..").normalize(),
    PathBuf::from(r"C:"),
);
Source

pub fn absolutize(&self) -> Result<PathBuf<T>>

Converts a path to an absolute form by normalizing the path, returning a PathBuf.

In the case that the path is relative, the current working directory is prepended prior to normalizing.

§Examples
use typed_path::{utils, Path, UnixEncoding};

// With an absolute path, it is just normalized
let path = Path::<UnixEncoding>::new("/a/b/../c/./d");
assert_eq!(path.absolutize().unwrap(), Path::new("/a/c/d"));

// With a relative path, it is first joined with the current working directory
// and then normalized
let cwd = utils::current_dir().unwrap().with_encoding::<UnixEncoding>();
let path = cwd.join(Path::new("a/b/../c/./d"));
assert_eq!(path.absolutize().unwrap(), cwd.join(Path::new("a/c/d")));
Source

pub fn join<P: AsRef<Path<T>>>(&self, path: P) -> PathBuf<T>

Creates an owned PathBuf with path adjoined to self.

See PathBuf::push for more details on what it means to adjoin a path.

§Examples
use typed_path::{Path, PathBuf, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
assert_eq!(
    Path::<UnixEncoding>::new("/etc").join("passwd"),
    PathBuf::from("/etc/passwd"),
);
Source

pub fn join_checked<P: AsRef<Path<T>>>( &self, path: P, ) -> Result<PathBuf<T>, CheckedPathError>

Creates an owned PathBuf with path adjoined to self, checking the path to ensure it is safe to join. When dealing with user-provided paths, this is the preferred method.

See PathBuf::push_checked for more details on what it means to adjoin a path safely.

§Examples
use typed_path::{CheckedPathError, Path, PathBuf, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("/etc");

// A valid path can be joined onto the existing one
assert_eq!(path.join_checked("passwd"), Ok(PathBuf::from("/etc/passwd")));

// An invalid path will result in an error
assert_eq!(path.join_checked("/sneaky/replacement"), Err(CheckedPathError::UnexpectedRoot));
Source

pub fn with_file_name<S: AsRef<[u8]>>(&self, file_name: S) -> PathBuf<T>

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

See PathBuf::set_file_name for more details.

§Examples
use typed_path::{Path, PathBuf, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("/tmp/foo.txt");
assert_eq!(path.with_file_name("bar.txt"), PathBuf::from("/tmp/bar.txt"));

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("/tmp");
assert_eq!(path.with_file_name("var"), PathBuf::from("/var"));
Source

pub fn with_extension<S: AsRef<[u8]>>(&self, extension: S) -> PathBuf<T>

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

See PathBuf::set_extension for more details.

§Examples
use typed_path::{Path, PathBuf, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("foo.rs");
assert_eq!(path.with_extension("txt"), PathBuf::from("foo.txt"));

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("foo.tar.gz");
assert_eq!(path.with_extension(""), PathBuf::from("foo.tar"));
assert_eq!(path.with_extension("xz"), PathBuf::from("foo.tar.xz"));
assert_eq!(path.with_extension("").with_extension("txt"), PathBuf::from("foo.txt"));
Source

pub fn components(&self) -> <T as Encoding>::Components<'_>

Produces an iterator over the Components of the path.

When parsing the path, there is a small amount of normalization:

  • Repeated separators are ignored, so a/b and a//b both have a and b as components.

  • Occurrences of . are normalized away, except if they are at the beginning of the path. For example, a/./b, a/b/, a/b/. and a/b all have a and b as components, but ./a/b starts with an additional CurDir component.

  • A trailing slash is normalized away, /a/b and /a/b/ are equivalent.

Note that no other normalization takes place; in particular, a/c and a/b/../c are distinct, to account for the possibility that b is a symbolic link (so its parent isn’t a).

§Examples
use typed_path::{Path, UnixComponent, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let mut components = Path::<UnixEncoding>::new("/tmp/foo.txt").components();

assert_eq!(components.next(), Some(UnixComponent::RootDir));
assert_eq!(components.next(), Some(UnixComponent::Normal(b"tmp")));
assert_eq!(components.next(), Some(UnixComponent::Normal(b"foo.txt")));
assert_eq!(components.next(), None)
Examples found in repository?
examples/unix.rs (line 6)
3fn main() {
4    let path = UnixPath::new(r"/path/to/file.txt");
5
6    for component in path.components() {
7        println!("{}", String::from_utf8_lossy(component.as_bytes()));
8    }
9}
More examples
Hide additional examples
examples/windows.rs (line 6)
3fn main() {
4    let path = WindowsPath::new(r"C:\path\to\file.txt");
5
6    for component in path.components() {
7        println!("{}", String::from_utf8_lossy(component.as_bytes()));
8    }
9}
Source

pub fn iter(&self) -> Iter<'_, T>

Produces an iterator over the path’s components viewed as [[u8]] slices.

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

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let mut it = Path::<UnixEncoding>::new("/tmp/foo.txt").iter();

assert_eq!(it.next(), Some(typed_path::constants::unix::SEPARATOR_STR.as_bytes()));
assert_eq!(it.next(), Some(b"tmp".as_slice()));
assert_eq!(it.next(), Some(b"foo.txt".as_slice()));
assert_eq!(it.next(), None)
Source

pub fn display(&self) -> Display<'_, T>

Returns an object that implements Display for safely printing paths that may contain non-Unicode data. This may perform lossy conversion, depending on the platform. If you would like an implementation which escapes the path please use Debug instead.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("/tmp/foo.rs");

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

pub fn with_encoding<U>(&self) -> PathBuf<U>
where U: Encoding,

Creates an owned PathBuf like self but with a different encoding.

§Note

As part of the process of converting between encodings, the path will need to be rebuilt. This involves pushing each component, which may result in differences in the resulting path such as resolving . and .. early or other unexpected side effects.

§Examples
use typed_path::{Path, UnixEncoding, WindowsEncoding};

// Convert from Unix to Windows
let unix_path = Path::<UnixEncoding>::new("/tmp/foo.txt");
let windows_path = unix_path.with_encoding::<WindowsEncoding>();
assert_eq!(windows_path, Path::<WindowsEncoding>::new(r"\tmp\foo.txt"));

// Converting from Windows to Unix will drop any prefix
let windows_path = Path::<WindowsEncoding>::new(r"C:\tmp\foo.txt");
let unix_path = windows_path.with_encoding::<UnixEncoding>();
assert_eq!(unix_path, Path::<UnixEncoding>::new(r"/tmp/foo.txt"));

// Converting to itself should retain everything
let path = Path::<WindowsEncoding>::new(r"C:\tmp\foo.txt");
assert_eq!(
    path.with_encoding::<WindowsEncoding>(),
    Path::<WindowsEncoding>::new(r"C:\tmp\foo.txt"),
);
Source

pub fn with_encoding_checked<U>(&self) -> Result<PathBuf<U>, CheckedPathError>
where U: Encoding,

Like with_encoding, creates an owned PathBuf like self but with a different encoding. Additionally, checks to ensure that the produced path will be valid.

§Note

As part of the process of converting between encodings, the path will need to be rebuilt. This involves pushing and checking each component, which may result in differences in the resulting path such as resolving . and .. early or other unexpected side effects.

§Examples
use typed_path::{CheckedPathError, Path, UnixEncoding, WindowsEncoding};

// Convert from Unix to Windows
let unix_path = Path::<UnixEncoding>::new("/tmp/foo.txt");
let windows_path = unix_path.with_encoding_checked::<WindowsEncoding>().unwrap();
assert_eq!(windows_path, Path::<WindowsEncoding>::new(r"\tmp\foo.txt"));

// Converting from Windows to Unix will drop any prefix
let windows_path = Path::<WindowsEncoding>::new(r"C:\tmp\foo.txt");
let unix_path = windows_path.with_encoding_checked::<UnixEncoding>().unwrap();
assert_eq!(unix_path, Path::<UnixEncoding>::new(r"/tmp/foo.txt"));

// Converting from Unix to Windows with invalid filename characters like `:` should fail
let unix_path = Path::<UnixEncoding>::new("/|invalid|/foo.txt");
assert_eq!(
    unix_path.with_encoding_checked::<WindowsEncoding>(),
    Err(CheckedPathError::InvalidFilename),
);

// Converting from Unix to Windows with unexpected prefix embedded in path should fail
let unix_path = Path::<UnixEncoding>::new("/path/c:/foo.txt");
assert_eq!(
    unix_path.with_encoding_checked::<WindowsEncoding>(),
    Err(CheckedPathError::UnexpectedPrefix),
);
Source

pub fn into_path_buf(self: Box<Path<T>>) -> PathBuf<T>

Converts a Box<Path> into a PathBuf without copying or allocating.

Source§

impl<T> Path<T>
where T: Encoding,

Source

pub fn has_platform_encoding(&self) -> bool
where T: 'static,

Returns true if the encoding is the platform abstraction (PlatformEncoding), otherwise returns false.

§Examples
use typed_path::{PlatformPath, UnixPath, WindowsPath};

assert!(PlatformPath::new("/some/path").has_platform_encoding());
assert!(!UnixPath::new("/some/path").has_platform_encoding());
assert!(!WindowsPath::new("/some/path").has_platform_encoding());
Source

pub fn with_platform_encoding(&self) -> PathBuf<PlatformEncoding>

Creates an owned PathBuf like self but using PlatformEncoding.

See Path::with_encoding for more information.

Source

pub fn with_platform_encoding_checked( &self, ) -> Result<PathBuf<PlatformEncoding>, CheckedPathError>

Creates an owned PathBuf like self but using PlatformEncoding, ensuring it is a valid platform path.

See Path::with_encoding_checked for more information.

Source§

impl<T> Path<T>
where T: Encoding,

Source

pub fn has_unix_encoding(&self) -> bool

Returns true if the encoding for the path is for Unix.

§Examples
use typed_path::{UnixPath, WindowsPath};

assert!(UnixPath::new("/some/path").has_unix_encoding());
assert!(!WindowsPath::new(r"\some\path").has_unix_encoding());
Examples found in repository?
examples/platform.rs (line 8)
3fn main() {
4    // You can create the path like normal, but it is a distinct encoding from Unix/Windows
5    let path = PlatformPath::new("some/path");
6
7    // The path will still behave like normal and even report its underlying encoding
8    assert_eq!(path.has_unix_encoding(), cfg!(unix));
9    assert_eq!(path.has_windows_encoding(), cfg!(windows));
10
11    // It can still be converted into specific platform paths
12    let _ = path.with_unix_encoding();
13    let _ = path.with_windows_encoding();
14}
Source

pub fn with_unix_encoding(&self) -> PathBuf<UnixEncoding>

Creates an owned PathBuf like self but using UnixEncoding.

See Path::with_encoding for more information.

Examples found in repository?
examples/platform.rs (line 12)
3fn main() {
4    // You can create the path like normal, but it is a distinct encoding from Unix/Windows
5    let path = PlatformPath::new("some/path");
6
7    // The path will still behave like normal and even report its underlying encoding
8    assert_eq!(path.has_unix_encoding(), cfg!(unix));
9    assert_eq!(path.has_windows_encoding(), cfg!(windows));
10
11    // It can still be converted into specific platform paths
12    let _ = path.with_unix_encoding();
13    let _ = path.with_windows_encoding();
14}
Source

pub fn with_unix_encoding_checked( &self, ) -> Result<PathBuf<UnixEncoding>, CheckedPathError>

Creates an owned PathBuf like self but using UnixEncoding, ensuring it is a valid Unix path.

See Path::with_encoding_checked for more information.

Source§

impl Path<UnixEncoding>

Source§

impl<T> Path<T>
where T: Encoding,

Source

pub fn has_windows_encoding(&self) -> bool

Returns true if the encoding for the path is for Windows.

§Examples
use typed_path::{UnixPath, WindowsPath};

assert!(!UnixPath::new("/some/path").has_windows_encoding());
assert!(WindowsPath::new(r"\some\path").has_windows_encoding());
Examples found in repository?
examples/platform.rs (line 9)
3fn main() {
4    // You can create the path like normal, but it is a distinct encoding from Unix/Windows
5    let path = PlatformPath::new("some/path");
6
7    // The path will still behave like normal and even report its underlying encoding
8    assert_eq!(path.has_unix_encoding(), cfg!(unix));
9    assert_eq!(path.has_windows_encoding(), cfg!(windows));
10
11    // It can still be converted into specific platform paths
12    let _ = path.with_unix_encoding();
13    let _ = path.with_windows_encoding();
14}
Source

pub fn with_windows_encoding(&self) -> PathBuf<WindowsEncoding>

Creates an owned PathBuf like self but using WindowsEncoding.

See Path::with_encoding for more information.

Examples found in repository?
examples/platform.rs (line 13)
3fn main() {
4    // You can create the path like normal, but it is a distinct encoding from Unix/Windows
5    let path = PlatformPath::new("some/path");
6
7    // The path will still behave like normal and even report its underlying encoding
8    assert_eq!(path.has_unix_encoding(), cfg!(unix));
9    assert_eq!(path.has_windows_encoding(), cfg!(windows));
10
11    // It can still be converted into specific platform paths
12    let _ = path.with_unix_encoding();
13    let _ = path.with_windows_encoding();
14}
Source

pub fn with_windows_encoding_checked( &self, ) -> Result<PathBuf<WindowsEncoding>, CheckedPathError>

Creates an owned PathBuf like self but using WindowsEncoding, ensuring it is a valid Windows path.

See Path::with_encoding_checked for more information.

Source§

impl Path<WindowsEncoding>

Trait Implementations§

Source§

impl<T> AsRef<[u8]> for Path<T>
where T: Encoding,

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<OsStr> for Path<T>
where T: Encoding,

Source§

fn as_ref(&self) -> &OsStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for [u8]
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for Cow<'_, [u8]>
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, T> AsRef<Path<T>> for Iter<'a, T>
where T: for<'enc> Encoding + 'a,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for OsStr
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for OsString
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for Path<T>
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for PathBuf<T>
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for String
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for UnixComponent<'_>
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for UnixComponents<'_>
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for Vec<u8>
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for WindowsComponent<'_>
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for WindowsComponents<'_>
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Path<T>> for str
where T: Encoding,

Source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Borrow<Path<T>> for PathBuf<T>
where T: Encoding,

Source§

fn borrow(&self) -> &Path<T>

Immutably borrows from an owned value. Read more
Source§

impl<T> Clone for Box<Path<T>>
where T: Encoding,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Path<T>
where T: Encoding,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Display for Path<T>
where T: Encoding,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format path by converting bytes to a String. This may perform lossy conversion, depending on the platform. If you would like an implementation which escapes the path please use Debug instead.

§Examples
use typed_path::{Path, UnixEncoding};

// NOTE: A path cannot be created on its own without a defined encoding
let path = Path::<UnixEncoding>::new("/tmp/foo.rs");

assert_eq!(path.to_string(), "/tmp/foo.rs");
Source§

impl<T> From<&Path<T>> for Arc<Path<T>>
where T: Encoding,

Source§

fn from(path: &Path<T>) -> Self

Converts a Path into an Arc by copying the Path data into a new Arc buffer.

Source§

impl<T> From<&Path<T>> for Box<Path<T>>
where T: Encoding,

Source§

fn from(path: &Path<T>) -> Self

Creates a boxed Path from a reference.

This will allocate and clone path to it.

Source§

impl<'a, T> From<&'a Path<T>> for Cow<'a, Path<T>>
where T: Encoding,

Source§

fn from(s: &'a Path<T>) -> Self

Creates a clone-on-write pointer from a reference to Path.

This conversion does not clone or allocate.

Source§

impl<T> From<&Path<T>> for Rc<Path<T>>
where T: Encoding,

Source§

fn from(path: &Path<T>) -> Self

Converts a Path into an Rc by copying the Path data into a new Rc buffer.

Source§

impl<T> From<Cow<'_, Path<T>>> for Box<Path<T>>
where T: Encoding,

Source§

fn from(cow: Cow<'_, Path<T>>) -> Box<Path<T>>

Creates a boxed Path from a clone-on-write pointer.

Converting from a Cow::Owned does not clone or allocate.

Source§

impl<T> From<PathBuf<T>> for Box<Path<T>>
where T: Encoding,

Source§

fn from(p: PathBuf<T>) -> Box<Path<T>>

Converts a PathBuf into a Box<Path>.

This conversion currently should not allocate memory, but this behavior is not guaranteed on all platforms or in all future versions.

Source§

impl<T> Hash for Path<T>
where T: Encoding,

Source§

fn hash<H: Hasher>(&self, h: &mut H)

Feeds this value into the given Hasher. Read more
Source§

impl<'a, T> IntoIterator for &'a Path<T>
where T: Encoding,

Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

type Item = &'a [u8]

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> Ord for Path<T>
where T: Encoding,

Source§

fn cmp(&self, other: &Path<T>) -> Ordering

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

impl<'a, T> PartialEq<&'a [u8]> for Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &&'a [u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<&'a Path<T>> for [u8]
where T: Encoding,

Source§

fn eq(&self, other: &&'a Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b, T> PartialEq<&'b Path<T>> for Cow<'a, Path<T>>
where T: Encoding,

Source§

fn eq(&self, other: &&'b Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b, T> PartialEq<&'a Path<T>> for Cow<'b, [u8]>
where T: Encoding,

Source§

fn eq(&self, other: &&'a Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<&'a Path<T>> for PathBuf<T>
where T: Encoding,

Source§

fn eq(&self, other: &&'a Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<&'a Path<T>> for Vec<u8>
where T: Encoding,

Source§

fn eq(&self, other: &&'a Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<[u8]> for &'a Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<[u8]> for Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<Cow<'a, [u8]>> for Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &Cow<'a, [u8]>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b, T> PartialEq<Cow<'a, Path<T>>> for &'b Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &Cow<'a, Path<T>>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<Cow<'a, Path<T>>> for Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &Cow<'a, Path<T>>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b, T> PartialEq<Cow<'b, [u8]>> for &'a Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &Cow<'b, [u8]>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<Path<T>> for &'a [u8]
where T: Encoding,

Source§

fn eq(&self, other: &Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<Path<T>> for [u8]
where T: Encoding,

Source§

fn eq(&self, other: &Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<Path<T>> for Cow<'a, [u8]>
where T: Encoding,

Source§

fn eq(&self, other: &Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<Path<T>> for Cow<'a, Path<T>>
where T: Encoding,

Source§

fn eq(&self, other: &Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<Path<T>> for PathBuf<T>
where T: Encoding,

Source§

fn eq(&self, other: &Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<Path<T>> for Vec<u8>
where T: Encoding,

Source§

fn eq(&self, other: &Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<PathBuf<T>> for &'a Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &PathBuf<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<PathBuf<T>> for Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &PathBuf<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialEq<Vec<u8>> for &'a Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &Vec<u8>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<Vec<u8>> for Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &Vec<u8>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq for Path<T>
where T: Encoding,

Source§

fn eq(&self, other: &Path<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> PartialOrd<&'a [u8]> for Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &&'a [u8]) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<&'a Path<T>> for [u8]
where T: Encoding,

Source§

fn partial_cmp(&self, other: &&'a Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, 'b, T> PartialOrd<&'b Path<T>> for Cow<'a, Path<T>>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &&'b Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, 'b, T> PartialOrd<&'a Path<T>> for Cow<'b, [u8]>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &&'a Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<&'a Path<T>> for PathBuf<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &&'a Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<&'a Path<T>> for Vec<u8>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &&'a Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<[u8]> for &'a Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> PartialOrd<[u8]> for Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<Cow<'a, [u8]>> for Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Cow<'a, [u8]>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, 'b, T> PartialOrd<Cow<'a, Path<T>>> for &'b Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Cow<'a, Path<T>>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<Cow<'a, Path<T>>> for Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Cow<'a, Path<T>>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, 'b, T> PartialOrd<Cow<'b, [u8]>> for &'a Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Cow<'b, [u8]>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<Path<T>> for &'a [u8]
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> PartialOrd<Path<T>> for [u8]
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<Path<T>> for Cow<'a, [u8]>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<Path<T>> for Cow<'a, Path<T>>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> PartialOrd<Path<T>> for PathBuf<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> PartialOrd<Path<T>> for Vec<u8>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<PathBuf<T>> for &'a Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &PathBuf<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> PartialOrd<PathBuf<T>> for Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &PathBuf<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> PartialOrd<Vec<u8>> for &'a Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Vec<u8>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> PartialOrd<Vec<u8>> for Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Vec<u8>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> PartialOrd for Path<T>
where T: Encoding,

Source§

fn partial_cmp(&self, other: &Path<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> ToOwned for Path<T>
where T: Encoding,

Source§

type Owned = PathBuf<T>

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

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

impl TryAsRef<Path<UnixEncoding>> for TypedPath<'_>

Source§

impl TryAsRef<Path<WindowsEncoding>> for TypedPath<'_>

Source§

impl<T> Eq for Path<T>
where T: Encoding,

Auto Trait Implementations§

§

impl<T> Freeze for Path<T>

§

impl<T> RefUnwindSafe for Path<T>
where T: RefUnwindSafe,

§

impl<T> Send for Path<T>
where T: Send,

§

impl<T> !Sized for Path<T>

§

impl<T> Sync for Path<T>
where T: Sync,

§

impl<T> Unpin for Path<T>
where T: Unpin,

§

impl<T> UnwindSafe for Path<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more