path

Struct path 

Source
pub struct path { /* private fields */ }
Expand description

’' are replaced by ‘/’

Implementations§

Source§

impl path

Source

pub const fn as_str(&self) -> &str

Source

pub const fn from_str(s: &str) -> &path

Source

pub const fn from_str_mut(s: &mut str) -> &mut path

Source§

impl path

Source

pub fn is_empty(&self) -> bool

Source

pub fn extension_or_empty(&self) -> &str

Returns the file extension of the path, if it exists.

The returned string slice does not include the dot ..

§Examples
use hexga_file_system::*;

assert_eq!(Path::new("foo/bar.txt").extension(), Some("txt"));
assert_eq!(Path::new("foo/archive.tar.gz").extension(), Some("gz"));
assert_eq!(Path::new("foo/bar").extension(), None);
Source

pub fn have_extension(&self) -> bool

Returns true if the path has a file extension.

§Examples
use hexga_file_system::*;

assert_eq!(Path::new("foo/bar.txt").have_extension(), true);
assert_eq!(Path::new("foo/archive.tar.gz").have_extension(), true);

assert_eq!(Path::new("foo/bar").have_extension(), false);
assert_eq!(Path::new("foo/.bar").have_extension(), false);
Source

pub fn without_extension(&self) -> &path

Returns a new path with the extension removed.

Equivalent to self.with_extension("").

§Examples
use hexga_file_system::*;

assert_eq!(Path::new("foo/bar.txt").without_extension().as_str(), "foo/bar");
assert_eq!(Path::new("foo/archive.tar.gz").without_extension().as_str(), "foo/archive");
assert_eq!(Path::new("foo/bar").without_extension().as_str(), "foo/bar");
Source

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

Returns the most file extensions of the path, if they exists.

The returned string slice does not include the first dot ..

§Examples
use hexga_file_system::*;

assert_eq!(Path::new("foo/bar.txt").extension(), Some("txt"));
assert_eq!(Path::new("foo/archive.tar.gz").extension(), Some("tar.gz"));
assert_eq!(Path::new("foo/bar").extension(), None);
Source

pub fn extensions( &self, ) -> impl Iterator<Item = &str> + DoubleEndedIterator + FusedIterator

Iter over all extensions, left to right

The returned extension does not include the dot ..

§Examples
use hexga_file_system::*;

assert_eq!(Path::new("foo/bar.txt").extensions().collect(), vec!["txt"]);
assert_eq!(Path::new("foo/archive.tar.gz").extension().collect(), vec!["tar", "gz"]);
assert_eq!(Path::new("foo/bar").extensions().collect(), vec![]);
assert_eq!(Path::new("foo/.bar").extensions().collect(), vec![]);
assert_eq!(Path::new("foo/.bar.txt").extensions().collect(), vec!["txt"]);
assert_eq!(Path::new("foo/.bar.txt").extensions().collect(), vec!["txt"]);
assert_eq!(Path::new("foo.buz/bar").extensions().collect(), vec![]);
Source

pub fn with_extension(&self, extension: &str) -> Path

Returns a new Path with its current extension replaced by the given extension.

This method replaces the file extension of the path with the provided one. If the path has no extension, the new one is simply appended.

A leading dot (.) in the provided extension is ignored automatically.

To remove the extension entirely, you can pass an empty string (""), but the the method Self::without_extension is more appropriate because it return a &path.

This method is a convenience wrapper over Self::with_extensions.

§Examples
use hexga_file_system::Path;

assert_eq!(Path::new("foo/bar.txt").with_extension("md").as_str(), "foo/bar.md");

// Leading dot is optional
assert_eq!(Path::new("foo/bar.txt").with_extension(".md").as_str(), "foo/bar.md");

// Remove the extension entirely
assert_eq!(Path::new("foo/bar.txt").with_extension("").as_str(), "foo/bar");

// Add a new extension if none existed
assert_eq!(Path::new("foo/bar").with_extension("md").as_str(), "foo/bar.md");

// Handle compound extensions
assert_eq!(Path::new("foo/archive").with_extension("tar.gz").as_str(), "foo/archive.tar.gz");
assert_eq!(Path::new("foo/archive").with_extension(".tar.gz").as_str(), "foo/archive.tar.gz");
Source

pub fn with_extensions<'a, E>(&'a self, extensions: E) -> Path
where E: IntoIterator<Item = &'a str>,

Returns a new Path with its extensions replaced by the given sequence of extensions.

Each extension is appended to the base filename, separated by a dot (.). This method can be used to build paths with compound extensions, such as "tar.gz".

§Examples
use hexga_file_system::Path;

assert_eq!(
    Path::new("foo/bar.txt").with_extensions(["tar", "gz"]).as_str(),
    "foo/bar.tar.gz"
);

assert_eq!(
    Path::new("foo/bar").with_extensions(["log"]).as_str(),
    "foo/bar.log"
);

assert_eq!(
    Path::new("foo/bar.tar.gz").with_extensions([]).as_str(),
    "foo/bar"
);
Source

pub fn iter( &self, ) -> impl Iterator<Item = &path> + DoubleEndedIterator + FusedIterator

Splits the path into its components using / as separators

§Examples
use hexga_file_system::*;

assert_eq!(Path::new("foo/bar/baz.txt").iter().collect(), vec!["foo", "bar", "baz.txt"]);
assert_eq!(Path::new("foo\\bar\\baz.txt").iter().collect(), vec!["foo", "bar", "baz.txt"]);
assert_eq!(Path::new("file.txt").iter().collect(), vec!["file.txt"]);
assert_eq!(Path::new("").iter().collect(), Vec::<String>::new());
assert_eq!(Path::new("/foo/bar/").iter().collect(), vec!["", "foo", "bar", ""]);
Source

pub fn parent_or_empty(&self) -> &path

Returns the parent directory of this path using Self::parent, or an empty path if none exists.

Source

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

Returns the parent directory of this path, if it exists.

The parent is defined as the portion of the path before the last / separator. If the path has no /, or if the parent would be empty, this returns None.

§Examples
use hexga_file_system::*;

let path = Path::new("foo/bar/baz.txt");
assert_eq!(path.parent().map(|p| p.as_str()), Some("foo/bar"));

let path = Path::new("foo/bar");
assert_eq!(path.parent().map(|p| p.as_str()), Some("foo"));


let path = Path::new("foo/bar/");
assert_eq!(path.parent().map(|p| p.as_str()), Some("foo/bar"));


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

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

pub fn push(&self, right: &path) -> Path

Source

pub fn name(&self) -> &str

Returns the name of the file or directory at the end of the path, without the file extensions (the portion before the most left final . in the filename).

If the path has no file name, returns an empty string "".

§Behavior
  • If the file name has no .: returns the entire file name.
  • If the file name begins with . and has no other dots: returns the entire file name (e.g., .gitignore).
  • Otherwise: returns the portion of the file name before the final ..
  • If the path ends with a directory separator or has no file name: returns "".
§Examples
use hexga_file_system::*;

assert_eq!(Path::new("foo/bar.txt").name(), "bar");
assert_eq!(Path::new("foo/.hidden").name(), ".hidden");
assert_eq!(Path::new("foo/archive.tar.gz").name(), "archive");
assert_eq!(Path::new("foo/bar/").name(), "");
assert_eq!(Path::new("file").name(), "file");
Source

pub fn with_name(&self, name: &str) -> Path

Returns a new file/folder name with the base name replaced by name, preserving the original extension(s).

The parent directory is not modified. Only the file/folder name is changed.

§Examples
use hexga_file_system::*;

assert_eq!("foo/bar.txt".with_name("baz"), "foo/baz.txt");
assert_eq!("foo/.hidden".with_name("config"), "foo/config");
assert_eq!("foo/.hidden.txt".with_name("config"), "foo/config.txt");
assert_eq!("foo/archive.tar.gz".with_name("new"), "foo/new.tar.gz");
assert_eq!("file".with_name("newfile"), "newfile");
Source

pub fn fullname(&self) -> &str

Returns the full file name (including all extensions) of the path.

If the path ends with a directory or has no file name, returns an empty string "".

§Examples
use hexga_file_system::*;

assert_eq!("foo/bar.txt".path_fullname(), "bar.txt");
assert_eq!("foo/.hidden".path_fullname(), ".hidden");
assert_eq!("foo/archive.tar.gz".path_fullname(), "archive.tar.gz");
assert_eq!("foo/bar/".path_fullname(), "");
assert_eq!("file".path_fullname(), "file");

Trait Implementations§

Source§

impl AsMut<path> for Path

Source§

fn as_mut(&mut self) -> &mut path

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

impl AsMut<str> for path

Source§

fn as_mut(&mut self) -> &mut str

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

impl AsRef<OsStr> for path

Source§

fn as_ref(&self) -> &OsStr

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

impl AsRef<path> for Path

Source§

fn as_ref(&self) -> &path

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

impl AsRef<path> for String

Source§

fn as_ref(&self) -> &path

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

impl AsRef<path> for path

Source§

fn as_ref(&self) -> &path

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

impl AsRef<path> for str

Source§

fn as_ref(&self) -> &path

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

impl AsRef<str> for path

Source§

fn as_ref(&self) -> &str

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

impl Borrow<path> for Path

Source§

fn borrow(&self) -> &path

Immutably borrows from an owned value. Read more
Source§

impl BorrowMut<path> for Path

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl Debug for path

Source§

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

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

impl Display for path

Source§

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

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

impl<'a, T> Div<T> for &'a mut path
where T: AsRef<str>,

Source§

type Output = Path

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> <&'a mut path as Div<T>>::Output

Performs the / operation. Read more
Source§

impl<'a, T> Div<T> for &'a path
where T: AsRef<str>,

Source§

type Output = Path

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> <&'a path as Div<T>>::Output

Performs the / operation. Read more
Source§

impl<'a> From<&'a mut path> for &'a mut str

Source§

fn from(value: &'a mut path) -> &'a mut str

Converts to this type from the input type.
Source§

impl<'a> From<&'a mut path> for Path

Source§

fn from(value: &'a mut path) -> Path

Converts to this type from the input type.
Source§

impl<'a> From<&'a mut str> for &'a mut path

Source§

fn from(value: &'a mut str) -> &'a mut path

Converts to this type from the input type.
Source§

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

Source§

fn from(value: &'a path) -> &'a str

Converts to this type from the input type.
Source§

impl<'a> From<&'a path> for Path

Source§

fn from(value: &'a path) -> Path

Converts to this type from the input type.
Source§

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

Source§

fn from(value: &'a str) -> &'a path

Converts to this type from the input type.
Source§

impl Hash for path

Source§

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

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

impl Ord for path

Source§

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

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

impl<'a> PartialEq<&'a path> for Path

Source§

fn eq(&self, other: &&'a path) -> bool

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

fn ne(&self, other: &&'a path) -> bool

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

impl<'a> PartialEq<&'a path> for path

Source§

fn eq(&self, other: &&'a path) -> bool

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

fn ne(&self, other: &&'a path) -> bool

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

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

Source§

fn eq(&self, other: &&'a str) -> bool

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

fn ne(&self, other: &&'a str) -> bool

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

impl PartialEq<String> for path

Source§

fn eq(&self, other: &String) -> bool

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

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

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

impl PartialEq<path> for Path

Source§

fn eq(&self, other: &path) -> bool

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

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

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

impl PartialEq<str> for path

Source§

fn eq(&self, other: &str) -> bool

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

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

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

impl PartialEq for path

Source§

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

Source§

fn partial_cmp(&self, other: &path) -> 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 Serialize for path

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToOwned for path

Source§

type Owned = Path

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> <path as ToOwned>::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 Eq for path

Source§

impl StructuralPartialEq for path

Auto Trait Implementations§

§

impl Freeze for path

§

impl RefUnwindSafe for path

§

impl Send for path

§

impl !Sized for path

§

impl Sync for path

§

impl Unpin for path

§

impl UnwindSafe for path

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

impl<T> CfgSerialize for T
where T: Serialize + ?Sized,