xur_

> module

std::path

path manipulation

use std::path; in the browser

std::path works with filesystem paths as strings, using the host's path rules. Most functions only look at the string; is_dir, is_file, exists and absolute look at the filesystem and need the fs feature.

> functions

# absolute(path: str) -> Result<str, Error>

The canonical absolute form of the path, with symbolic links and ./.. resolved. The path must exist. The error is the shared io::Error (see xur.std.io(7)), such as Err(io::Error::NotFound) if the path does not exist.

# components(path: str) -> list<str>

The components of the path, such as ["/", "usr", "bin"] for "/usr/bin".

# exists(path: str) -> bool

Whether the path exists.

# extension(path: str) -> Option<str>

The file name's last extension, without the dot ("gz" for "archive.tar.gz"); None if there is none.

# file_name(path: str) -> Option<str>

The last component, or None if the path ends in ...

# is_absolute(path: str) -> bool

Whether the path is absolute or relative.

# is_dir(path: str) -> bool

Whether the path exists and is a directory, or a file. Symbolic links are followed.

# is_file(path: str) -> bool

Whether the path exists and is a directory, or a file. Symbolic links are followed.

# is_relative(path: str) -> bool

Whether the path is absolute or relative.

# join(parts?: str) -> str

Joins the parts with the path separator. A part that is an absolute path replaces everything before it. With no parts it returns "".

# parent(path: str) -> Option<str>

The path without its last component; None for a root or empty path. A bare file name has the parent "".

# stem(path: str) -> Option<str>

The file name without its last extension ("archive.tar" for "archive.tar.gz").

# with_extension(path: str, ext: str) -> str

The path with its extension replaced by ext, or added if it has none. An empty ext removes the extension.

> examples

use std::path;
use std::io;

fn main() {
    let p = path::join("/usr", "local", "bin");
    io::println("{}", p);
    io::println("parent: {}", path::parent(p).unwrap());
    io::println("ext: {}", path::extension("file.tar.gz").unwrap());
}