Rust PathBuf Examples
These are examples of the functions and features available in Rusts PathBuf
This is a work in progress making examples from >this page>https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.display>
Pop
use PathBuf;
Output:
/Users/alan/Desktop
NOTE: the pop just returns true not the item that was popped as far as I can tell
Set Extension
Output:
/Users/alan/Desktop/alfa.v1.neo
Set File Name
Output:
/Users/alan/Desktop/bravo.v2.txt
Ancestors
Output:
/Users/alan/Desktop/alfa.v1.txt
/Users/alan/Desktop
/Users/alan
/Users
/
Canonicalize
Output:
/Users/alan/Desktop/alfa.v1.txt
Components
Output:
// Makes an iterator that produces this
Components(
[
RootDir,
Normal(
"Users",
),
Normal(
"alan",
),
Normal(
"Desktop",
),
Normal(
"alfa.v1.txt",
),
],
)
Display Name
Output:
/Users/alan/Desktop/alfa.v1.txt
Extension
Output:
txt
File Name
Output:
alfa.v1.txt
File Stem
(There's a file_prefix
that's in nightly as well that will do a similar thing as thise but return alfa
instead)
Output:
alfa.v1
Join Paths
This creates a new path from the joined parts
Output:
/Users/alan/Desktop/alfa.v1.txt
Metadata
Output:
Metadata {
file_type: FileType(
FileType {
mode: 33188,
},
),
is_dir: false,
is_file: true,
permissions: Permissions(
FilePermissions {
mode: 33188,
},
),
accessed: Ok(
SystemTime {
tv_sec: 1680741445,
tv_nsec: 46423762,
},
),
..
}
Parent
Output:
/Users/alan/Desktop/alfa.v1.txt
Strip Prefix
Output:
Desktop/alfa.v1.txt
-- end of line --