mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-16 02:22:41 +00:00
36 lines
855 B
Rust
36 lines
855 B
Rust
// ./src/std_misc/path.md
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
fn part0() {
|
|
// Create a `Path` from an `&'static str`
|
|
let path = Path::new(".");
|
|
|
|
// The `display` method returns a `Display`able structure
|
|
let _display = path.display();
|
|
|
|
// `join` merges a path with a byte container using the OS specific
|
|
// separator, and returns a `PathBuf`
|
|
let mut new_path = path.join("a").join("b");
|
|
|
|
// `push` extends the `PathBuf` with a `&Path`
|
|
new_path.push("c");
|
|
new_path.push("myfile.tar.gz");
|
|
|
|
// `set_file_name` updates the file name of the `PathBuf`
|
|
new_path.set_file_name("package.tgz");
|
|
|
|
// Convert the `PathBuf` into a string slice
|
|
match new_path.to_str() {
|
|
None => panic!("new path is not a valid UTF-8 sequence"),
|
|
Some(s) => println!("new path is {}", s),
|
|
}
|
|
}
|
|
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|