OxL Reference

data Path

Text operations on /-separated paths; nothing touches the file system.

Example:

oxl✓ checked in CI
use std.io { Path }

fn main() io {
  let p = Path.of("/var/log") / "app.log"
  print("{p.show()} {p.isAbsolute()}")
}
Output
/var/log/app.log true

Examples#

Recipes for paths: parts of a path, joining, normalization.

Parts of a path and joining#

Path does not touch the file system: it is pure string work (fileName, stem, extension, parent, normalize, the / operator).

oxl✓ checked in CI
use std.io { Path }

fn main() io {
  let p = Path.of("/srv/app/config/prod.toml")
  print("{p.fileName()} {p.stem()} {p.extension()}")  // name, name without extension, extension
  print("{p.parent() ?? Path.of("/")}")
  print("{p.withExtension("json")}")
  print("{p.isAbsolute()} {Path.of("rel/x").isAbsolute()}")
  let joined = Path.of("/srv") / "app" / "logs"  // the / operator joins segments
  print("{joined}")
  print("{Path.of("/a/b/../c/./d").normalize()}")
  print("{p.components()}")
}
Output
prod.toml prod toml
/srv/app/config
/srv/app/config/prod.json
true false
/srv/app/logs
/a/c/d
["srv", "app", "config", "prod.toml"]
@derive(Eq, Hash)
pub(api) data Path

Thread safety. an immutable value.

Since. 1.0.0-beta

Fields

pub(api) text: str

The path as text.

Methods

of(text: str) -> Path
The path with this text.
join(other: str) -> Path
Path.of("a/b").join("c") is a/b/c; an absolute right side replaces the left; empty parts are ignored.
/(a: Path, b: str) -> Path
Joins a path and a segment with / (an absolute b replaces a).
isAbsolute() -> bool
Whether the path starts with /.
fileName() -> str
Last component (a/b.txt -> b.txt; / and the empty path -> empty).
parent() -> Path?
Everything before the last component (a/b/c -> a/b, a -> empty, /a -> /), none for / and the empty path.
extension() -> str
Extension of the file name without the dot (a.tar.gz -> gz); empty if none; .bashrc has none.
stem() -> str
File name without the extension (a.tar.gz -> a.tar).
withExtension(ext: str) -> Path
The path with its extension replaced by ext (added when there is none).
components() -> List<str>
Non-empty components (/a//b/ -> a, b).
normalize() -> Path
Removes . components and folds ..
show() -> str
The path as text.
toString() -> str
The path as text.

Defined in: std/io/io.oxl:826

See also

OxL 1.0.0-beta · Documentation version 1.0.0-beta© OxwaldLink · generated from the Standard, the std sources and the guides