Enum Utf8TypedPathBuf

Source
pub enum Utf8TypedPathBuf {
    Unix(Utf8UnixPathBuf),
    Windows(Utf8WindowsPathBuf),
}
Expand description

Represents a pathbuf with a known type that can be one of:

Variants§

Implementations§

Source§

impl Utf8TypedPathBuf

Source

pub fn is_unix(&self) -> bool

Returns true if this path represents a Unix path.

Source

pub fn is_windows(&self) -> bool

Returns true if this path represents a Windows path.

Source

pub fn with_unix_encoding(&self) -> Utf8TypedPathBuf

Converts this Utf8TypedPathBuf into the Unix variant.

Source

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

Converts this Utf8TypedPathBuf into the Unix variant, ensuring it is valid as a Unix path.

Source

pub fn with_windows_encoding(&self) -> Utf8TypedPathBuf

Converts this Utf8TypedPathBuf into the Windows variant.

Source

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

Converts this Utf8TypedPathBuf into the Windows variant, ensuring it is valid as a Windows path.

Source

pub fn new(type: PathType) -> Self

Allocates an empty Utf8TypedPathBuf for the specified path type.

§Examples
use typed_path::{PathType, Utf8TypedPathBuf};
let _unix_path = Utf8TypedPathBuf::new(PathType::Unix);
let _windows_path = Utf8TypedPathBuf::new(PathType::Windows);
Source

pub fn unix() -> Self

Allocates an empty Utf8TypedPathBuf as a Unix path.

Source

pub fn windows() -> Self

Allocates an empty Utf8TypedPathBuf as a Windows path.

Source

pub fn from_unix(s: impl AsRef<str>) -> Self

Creates a new Utf8TypedPathBuf from the bytes representing a Unix path.

§Examples
use typed_path::Utf8TypedPathBuf;
let path = Utf8TypedPathBuf::from_unix("/tmp");
Source

pub fn from_windows(s: impl AsRef<str>) -> Self

Creates a new Utf8TypedPathBuf from the bytes representing a Windows path.

§Examples
use typed_path::Utf8TypedPathBuf;
let path = Utf8TypedPathBuf::from_windows(r"C:\tmp");
Source

pub fn to_path(&self) -> Utf8TypedPath<'_>

Converts into a Utf8TypedPath.

Source

pub fn push(&mut self, path: impl AsRef<str>)

Extends self with path.

If path is absolute, it replaces the current path.

With Utf8WindowsPathBuf:

  • if path has a root but no prefix (e.g., \windows), it replaces everything except for the prefix (if any) of self.
  • if path has a prefix but no root, it replaces self.
  • if self has a verbatim prefix (e.g. \\?\C:\windows) and path is not empty, the new path is normalized: all references to . and .. are removed.
§Difference from PathBuf

Unlike Utf8PathBuf::push, this implementation only supports types that implement AsRef<str> instead of AsRef<Path>.

§Examples

Pushing a relative path extends the existing path:

use typed_path::Utf8TypedPathBuf;

let mut path = Utf8TypedPathBuf::from_unix("/tmp");
path.push("file.bk");
assert_eq!(path, Utf8TypedPathBuf::from_unix("/tmp/file.bk"));

Pushing an absolute path replaces the existing path:

use typed_path::Utf8TypedPathBuf;

let mut path = Utf8TypedPathBuf::from_unix("/tmp");
path.push("/etc");
assert_eq!(path, Utf8TypedPathBuf::from_unix("/etc"));
Source

pub fn push_checked( &mut self, path: impl AsRef<str>, ) -> Result<(), CheckedPathError>

Like Utf8TypedPathBuf::push, extends self with path, but also checks to ensure that path abides by a set of rules.

§Rules
  1. path cannot contain a prefix component.
  2. path cannot contain a root component.
  3. path cannot contain invalid filename bytes.
  4. path cannot contain parent components such that the current path would be escaped.
§Difference from PathBuf

Unlike PathBuf::push_checked, this implementation only supports types that implement AsRef<str> instead of AsRef<Path>.

§Examples

Pushing a relative path extends the existing path:

use typed_path::Utf8TypedPathBuf;

let mut path = Utf8TypedPathBuf::from_unix("/tmp");
assert!(path.push_checked("file.bk").is_ok());
assert_eq!(path, Utf8TypedPathBuf::from_unix("/tmp/file.bk"));

Pushing a relative path that contains unresolved parent directory references fails with an error:

use typed_path::{CheckedPathError, Utf8TypedPathBuf};

let mut path = Utf8TypedPathBuf::from_unix("/tmp");

// Pushing a relative path that contains parent directory references that cannot be
// resolved within the path is considered an error as this is considered a path
// traversal attack!
assert_eq!(path.push_checked(".."), Err(CheckedPathError::PathTraversalAttack));
assert_eq!(path, Utf8TypedPathBuf::from("/tmp"));

Pushing an absolute path fails with an error:

use typed_path::{CheckedPathError, Utf8TypedPathBuf};

let mut path = Utf8TypedPathBuf::from_unix("/tmp");

// Pushing an absolute path will fail with an error
assert_eq!(path.push_checked("/etc"), Err(CheckedPathError::UnexpectedRoot));
assert_eq!(path, Utf8TypedPathBuf::from_unix("/tmp"));
Source

pub fn pop(&mut self) -> bool

Truncates self to self.parent.

Returns false and does nothing if self.parent is None. Otherwise, returns true.

§Examples
use typed_path::{Utf8TypedPath, Utf8TypedPathBuf};

let mut p = Utf8TypedPathBuf::from_unix("/spirited/away.rs");

p.pop();
assert_eq!(Utf8TypedPath::derive("/spirited"), p);
p.pop();
assert_eq!(Utf8TypedPath::derive("/"), p);
Source

pub fn set_file_name<S: AsRef<str>>(&mut self, file_name: S)

Updates self.file_name to file_name.

If self.file_name was None, this is equivalent to pushing file_name.

Otherwise it is equivalent to calling pop and then pushing file_name. The new path will be a sibling of the original path. (That is, it will have the same parent.)

§Examples
use typed_path::Utf8TypedPathBuf;

let mut buf = Utf8TypedPathBuf::from_unix("/");
assert!(buf.file_name() == None);
buf.set_file_name("bar");
assert!(buf == Utf8TypedPathBuf::from_unix("/bar"));
assert!(buf.file_name().is_some());
buf.set_file_name("baz.txt");
assert!(buf == Utf8TypedPathBuf::from_unix("/baz.txt"));
Source

pub fn set_extension<S: AsRef<str>>(&mut self, extension: S) -> bool

Updates self.extension to extension.

Returns false and does nothing if self.file_name is None, returns true and updates the extension otherwise.

If self.extension is None, the extension is added; otherwise it is replaced.

§Examples
use typed_path::{Utf8TypedPath, Utf8TypedPathBuf};

let mut p = Utf8TypedPathBuf::from_unix("/feel/the");

p.set_extension("force");
assert_eq!(Utf8TypedPath::derive("/feel/the.force"), p.to_path());

p.set_extension("dark_side");
assert_eq!(Utf8TypedPath::derive("/feel/the.dark_side"), p.to_path());
Source

pub fn into_string(self) -> String

Consumes the Utf8TypedPathBuf, yielding its internal String storage.

§Examples
use typed_path::Utf8TypedPathBuf;

let p = Utf8TypedPathBuf::from_unix("/the/head");
let string = p.into_string();
assert_eq!(string, "/the/head");
Source

pub fn capacity(&self) -> usize

Invokes capacity on the underlying instance of Vec.

Source

pub fn clear(&mut self)

Invokes clear on the underlying instance of Vec.

Source

pub fn reserve(&mut self, additional: usize)

Invokes reserve on the underlying instance of Vec.

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Invokes try_reserve on the underlying instance of Vec.

Source

pub fn reserve_exact(&mut self, additional: usize)

Invokes reserve_exact on the underlying instance of Vec.

Source

pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>

Invokes try_reserve_exact on the underlying instance of Vec.

Source

pub fn shrink_to_fit(&mut self)

Invokes shrink_to_fit on the underlying instance of Vec.

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Invokes shrink_to on the underlying instance of Vec.

Source§

impl Utf8TypedPathBuf

Reimplementation of Utf8TypedPath methods as we cannot implement std::ops::Deref directly.

Source

pub fn as_str(&self) -> &str

Yields the underlying str slice.

§Examples
use typed_path::Utf8TypedPathBuf;

let string = Utf8TypedPathBuf::from("foo.txt").as_str().to_string();
assert_eq!(string, "foo.txt");
Source

pub fn is_absolute(&self) -> bool

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

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

  • On Windows (Utf8WindowsPathBuf), 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::Utf8TypedPathBuf;

assert!(!Utf8TypedPathBuf::from("foo.txt").is_absolute());
Source

pub fn is_relative(&self) -> bool

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

See is_absolute’s documentation for more details.

§Examples
use typed_path::Utf8TypedPathBuf;

assert!(Utf8TypedPathBuf::from("foo.txt").is_relative());
Source

pub fn has_root(&self) -> bool

Returns true if the Utf8TypedPathBuf has a root.

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

  • On Windows (Utf8WindowsPathBuf), 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::Utf8TypedPathBuf;

assert!(Utf8TypedPathBuf::from("/etc/passwd").has_root());
Source

pub fn parent(&self) -> Option<Utf8TypedPath<'_>>

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

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

§Examples
use typed_path::Utf8TypedPathBuf;

let path = Utf8TypedPathBuf::from("/foo/bar");
let parent = path.parent().unwrap();
assert_eq!(parent, Utf8TypedPathBuf::from("/foo"));

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

pub fn ancestors(&self) -> Utf8TypedAncestors<'_>

Produces an iterator over Utf8TypedPathBuf and its ancestors.

The iterator will yield the Utf8TypedPathBuf 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::{Utf8TypedPath, Utf8TypedPathBuf};

let path = Utf8TypedPathBuf::from("/foo/bar");
let mut ancestors = path.ancestors();
assert_eq!(ancestors.next(), Some(Utf8TypedPath::derive("/foo/bar")));
assert_eq!(ancestors.next(), Some(Utf8TypedPath::derive("/foo")));
assert_eq!(ancestors.next(), Some(Utf8TypedPath::derive("/")));
assert_eq!(ancestors.next(), None);

let path = Utf8TypedPathBuf::from("../foo/bar");
let mut ancestors = path.ancestors();
assert_eq!(ancestors.next(), Some(Utf8TypedPath::derive("../foo/bar")));
assert_eq!(ancestors.next(), Some(Utf8TypedPath::derive("../foo")));
assert_eq!(ancestors.next(), Some(Utf8TypedPath::derive("..")));
assert_eq!(ancestors.next(), Some(Utf8TypedPath::derive("")));
assert_eq!(ancestors.next(), None);
Source

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

Returns the final component of the Utf8TypedPathBuf, 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::Utf8TypedPathBuf;

assert_eq!(Some("bin"), Utf8TypedPathBuf::from("/usr/bin/").file_name());
assert_eq!(Some("foo.txt"), Utf8TypedPathBuf::from("tmp/foo.txt").file_name());
assert_eq!(Some("foo.txt"), Utf8TypedPathBuf::from("foo.txt/.").file_name());
assert_eq!(Some("foo.txt"), Utf8TypedPathBuf::from("foo.txt/.//").file_name());
assert_eq!(None, Utf8TypedPathBuf::from("foo.txt/..").file_name());
assert_eq!(None, Utf8TypedPathBuf::from("/").file_name());
Source

pub fn strip_prefix( &self, base: impl AsRef<str>, ) -> Result<Utf8TypedPath<'_>, StripPrefixError>

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::{Utf8TypedPath, Utf8TypedPathBuf};

let path = Utf8TypedPathBuf::from("/test/haha/foo.txt");

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

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

let prefix = Utf8TypedPathBuf::from("/test/");
assert_eq!(path.strip_prefix(prefix), Ok(Utf8TypedPath::derive("haha/foo.txt")));
Source

pub fn starts_with(&self, base: impl AsRef<str>) -> bool

Determines whether base is a prefix of self.

Only considers whole path components to match.

§Difference from Path

Unlike Utf8Path::starts_with, this implementation only supports types that implement AsRef<str> instead of AsRef<Path>.

§Examples
use typed_path::Utf8TypedPathBuf;

let path = Utf8TypedPathBuf::from("/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!(!Utf8TypedPathBuf::from("/etc/foo.rs").starts_with("/etc/foo"));
Source

pub fn ends_with(&self, child: impl AsRef<str>) -> bool

Determines whether child is a suffix of self.

Only considers whole path components to match.

§Difference from Path

Unlike Utf8Path::ends_with, this implementation only supports types that implement AsRef<str> instead of AsRef<Path>.

§Examples
use typed_path::Utf8TypedPathBuf;

let path = Utf8TypedPathBuf::from("/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<&str>

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::Utf8TypedPathBuf;

assert_eq!("foo", Utf8TypedPathBuf::from("foo.rs").file_stem().unwrap());
assert_eq!("foo.tar", Utf8TypedPathBuf::from("foo.tar.gz").file_stem().unwrap());
Source

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

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::Utf8TypedPathBuf;

assert_eq!("rs", Utf8TypedPathBuf::from("foo.rs").extension().unwrap());
assert_eq!("gz", Utf8TypedPathBuf::from("foo.tar.gz").extension().unwrap());
Source

pub fn normalize(&self) -> Utf8TypedPathBuf

Returns an owned Utf8TypedPathBuf 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::Utf8TypedPathBuf;

assert_eq!(
    Utf8TypedPathBuf::from("foo/bar//baz/./asdf/quux/..").normalize(),
    Utf8TypedPathBuf::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::Utf8TypedPathBuf;

assert_eq!(
    Utf8TypedPathBuf::from("/../foo").normalize(),
    Utf8TypedPathBuf::from("/foo"),
);

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

use typed_path::Utf8TypedPathBuf;

assert_eq!(
    Utf8TypedPathBuf::from("../foo/..").normalize(),
    Utf8TypedPathBuf::from(""),
);

// Windows prefixes also count this way, but the prefix remains
assert_eq!(
    Utf8TypedPathBuf::from(r"C:..\foo\..").normalize(),
    Utf8TypedPathBuf::from(r"C:"),
);
Source

pub fn absolutize(&self) -> Result<Utf8TypedPathBuf>

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

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

§Examples
use typed_path::{utils, Utf8TypedPathBuf, Utf8UnixEncoding};

// With an absolute path, it is just normalized
let path = Utf8TypedPathBuf::from("/a/b/../c/./d");
assert_eq!(path.absolutize().unwrap(), Utf8TypedPathBuf::from("/a/c/d"));

// With a relative path, it is first joined with the current working directory
// and then normalized
let cwd = utils::utf8_current_dir().unwrap()
    .with_encoding::<Utf8UnixEncoding>().to_typed_path_buf();

let path = cwd.join("a/b/../c/./d");
assert_eq!(path.absolutize().unwrap(), cwd.join("a/c/d"));
Source

pub fn join(&self, path: impl AsRef<str>) -> Utf8TypedPathBuf

Creates an owned Utf8TypedPathBuf with path adjoined to self.

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

§Difference from Path

Unlike Utf8Path::join, this implementation only supports types that implement AsRef<str> instead of AsRef<Path>.

§Examples
use typed_path::Utf8TypedPathBuf;

assert_eq!(
    Utf8TypedPathBuf::from("/etc").join("passwd"),
    Utf8TypedPathBuf::from("/etc/passwd"),
);
Source

pub fn join_checked( &self, path: impl AsRef<str>, ) -> Result<Utf8TypedPathBuf, CheckedPathError>

Creates an owned Utf8TypedPathBuf 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 Utf8TypedPathBuf::push_checked for more details on what it means to adjoin a path safely.

§Difference from Path

Unlike Utf8Path::join_checked, this implementation only supports types that implement AsRef<str> instead of AsRef<Path>.

§Examples
use typed_path::{CheckedPathError, Utf8TypedPathBuf};

// Valid path will join successfully
assert_eq!(
    Utf8TypedPathBuf::from("/etc").join_checked("passwd"),
    Ok(Utf8TypedPathBuf::from("/etc/passwd")),
);

// Invalid path will fail to join
assert_eq!(
    Utf8TypedPathBuf::from("/etc").join_checked("/sneaky/path"),
    Err(CheckedPathError::UnexpectedRoot),
);
Source

pub fn with_file_name<S: AsRef<str>>(&self, file_name: S) -> Utf8TypedPathBuf

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

See Utf8TypedPathBuf::set_file_name for more details.

§Examples
use typed_path::Utf8TypedPathBuf;

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

let path = Utf8TypedPathBuf::from("/tmp");
assert_eq!(path.with_file_name("var"), Utf8TypedPathBuf::from("/var"));
Source

pub fn with_extension<S: AsRef<str>>(&self, extension: S) -> Utf8TypedPathBuf

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

See Utf8TypedPathBuf::set_extension for more details.

§Examples
use typed_path::Utf8TypedPathBuf;

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

let path = Utf8TypedPathBuf::from("foo.tar.gz");
assert_eq!(path.with_extension(""), Utf8TypedPathBuf::from("foo.tar"));
assert_eq!(path.with_extension("xz"), Utf8TypedPathBuf::from("foo.tar.xz"));
assert_eq!(path.with_extension("").with_extension("txt"), Utf8TypedPathBuf::from("foo.txt"));
Source

pub fn components(&self) -> Utf8TypedComponents<'_>

Produces an iterator over the Utf8TypedComponents 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::{Utf8TypedPathBuf, Utf8TypedComponent};

let path = Utf8TypedPathBuf::from("/tmp/foo.txt");
let mut components = path.components();

assert!(components.next().unwrap().is_root());
assert_eq!(components.next().unwrap().as_normal_str(), Some("tmp"));
assert_eq!(components.next().unwrap().as_normal_str(), Some("foo.txt"));
assert_eq!(components.next(), None)
Source

pub fn iter(&self) -> Utf8TypedIter<'_>

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 typed_path::Utf8TypedPathBuf;

let path = Utf8TypedPathBuf::from("/tmp/foo.txt");
let mut it = path.iter();

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

Trait Implementations§

Source§

impl AsRef<[u8]> for Utf8TypedPathBuf

Source§

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

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

impl AsRef<str> for Utf8TypedPathBuf

Source§

fn as_ref(&self) -> &str

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

impl Clone for Utf8TypedPathBuf

Source§

fn clone(&self) -> Utf8TypedPathBuf

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 Debug for Utf8TypedPathBuf

Source§

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

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

impl Display for Utf8TypedPathBuf

Source§

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

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

impl<'a> From<&'a str> for Utf8TypedPathBuf

Source§

fn from(s: &'a str) -> Self

Creates a new typed pathbuf from a byte slice by determining if the path represents a Windows or Unix path. This is accomplished by first trying to parse as a Windows path. If the resulting path contains a prefix such as C: or begins with a \, it is assumed to be a Utf8WindowsPathBuf; otherwise, the slice will be represented as a Utf8UnixPathBuf.

§Examples
use typed_path::Utf8TypedPathBuf;

assert!(Utf8TypedPathBuf::from(r#"C:\some\path\to\file.txt"#).is_windows());
assert!(Utf8TypedPathBuf::from(r#"\some\path\to\file.txt"#).is_windows());
assert!(Utf8TypedPathBuf::from(r#"/some/path/to/file.txt"#).is_unix());

// NOTE: If we don't start with a backslash, it's too difficult to
//       determine and we therefore just assume a Unix/POSIX path.
assert!(Utf8TypedPathBuf::from(r#"some\path\to\file.txt"#).is_unix());
assert!(Utf8TypedPathBuf::from("file.txt").is_unix());
assert!(Utf8TypedPathBuf::from("").is_unix());
Source§

impl From<String> for Utf8TypedPathBuf

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl Hash for Utf8TypedPathBuf

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

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

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Utf8TypedPathBuf

Source§

fn cmp(&self, other: &Utf8TypedPathBuf) -> Ordering

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

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a> PartialEq<&'a str> for Utf8TypedPathBuf

Source§

fn eq(&self, path: &&'a str) -> 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 PartialEq<Utf8TypedPath<'_>> for Utf8TypedPathBuf

Source§

fn eq(&self, path: &Utf8TypedPath<'_>) -> 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 PartialEq<Utf8TypedPathBuf> for &str

Source§

fn eq(&self, path: &Utf8TypedPathBuf) -> 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 PartialEq<Utf8TypedPathBuf> for Utf8TypedPath<'_>

Source§

fn eq(&self, path: &Utf8TypedPathBuf) -> 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 PartialEq<Utf8TypedPathBuf> for str

Source§

fn eq(&self, path: &Utf8TypedPathBuf) -> 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 PartialEq<str> for Utf8TypedPathBuf

Source§

fn eq(&self, path: &str) -> 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 PartialEq for Utf8TypedPathBuf

Source§

fn eq(&self, other: &Utf8TypedPathBuf) -> 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 PartialOrd for Utf8TypedPathBuf

Source§

fn partial_cmp(&self, other: &Utf8TypedPathBuf) -> 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 TryFrom<Utf8TypedPathBuf> for Utf8UnixPathBuf

Source§

type Error = Utf8TypedPathBuf

The type returned in the event of a conversion error.
Source§

fn try_from(path: Utf8TypedPathBuf) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Utf8TypedPathBuf> for Utf8WindowsPathBuf

Source§

type Error = Utf8TypedPathBuf

The type returned in the event of a conversion error.
Source§

fn try_from(path: Utf8TypedPathBuf) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Utf8TypedPathBuf

Source§

impl StructuralPartialEq for Utf8TypedPathBuf

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.