OxL Справочник OxL
РусскийEnglish

data Path

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

Example:

oxl✓ проверяется в CI
use std.io { Path }

fn main() io {
  let p = Path.of("/var/log") / "app.log"
  print("{p.show()} {p.isAbsolute()}")
}
Вывод
/var/log/app.log true
@derive(Eq, Hash)
pub(api) data Path

Потокобезопасность. an immutable value.

С версии. 1.0.0-beta

Поля

pub(api) text: str

The path as text.

Методы

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.

Определено в: std/io/io.oxl:814

См. также