std::path
Filesystem Paths
Owned, mutable filesystem path type for building, inspecting, and decomposing POSIX paths.
All public API lives under the Path namespace (imported as
Path from "std::path").
Types
| Type | Description |
|---|---|
PathBuf |
Owned path backed by a String — the main type |
Constructors
| Method | Source | Cost |
|---|---|---|
PathBuf::new() |
(empty) | One String alloc |
PathBuf::create(s) |
str literal |
Copy into String |
PathBuf::fromString(s) |
&String |
Clone the String |
Query Methods
| Method | Returns | Description |
|---|---|---|
isEmpty |
boolean |
True if the path has no bytes |
isAbsolute |
boolean |
True if the path starts with / |
isRelative |
boolean |
True if the path does not start with / |
asStr |
str |
Borrow as const char* (NUL-terminated) |
toString |
String |
Clone the inner String |
fileName |
Option<String> |
Last component after final / |
extension |
Option<String> |
After last . in fileName |
parent |
Option<PathBuf> |
Everything before last component |
Mutation Methods
| Method | Signature | Description |
|---|---|---|
push |
push(&mut self, part: str): void |
Append a path component |
pop |
pop(&mut self): boolean |
Remove the last component |
Operations (return new PathBuf)
| Method | Signature | Description |
|---|---|---|
join |
join(&self, part: str): PathBuf |
Clone self, then push part |
normalize |
normalize(&self): PathBuf |
Lexically resolve ./.. |
Platform Notes
This module is POSIX-oriented: the separator is / and there is
no drive-letter or UNC prefix handling. Windows support will be added
when @platform attributes land.
Design Decisions
- No
Path(borrowed view) type yet. Ignisstrisconst char*with no length — it cannot represent a sub-range without copying. A borrowedPathwill be added when string slices land. fileName,extension, andparentreturn owned values (String / PathBuf) because there is no zero-copy substring today.pushwith an absolute path (/...) replaces self entirely, matching POSIXjoinsemantics (and Rust’sPathBuf::push).
Example
import Path from "std::path";
import Option from "std::option";
function main(): i32 {
let mut p: Path::PathBuf = Path::PathBuf::create("/usr/local");
p.push("bin");
p.push("ignis");
// p.asStr() == "/usr/local/bin/ignis"
let name: Option<String> = p.fileName();
// name == Option::SOME("ignis")
let ext: Option<String> = p.extension();
// ext == Option::NONE (no extension)
let par: Option<Path::PathBuf> = p.parent();
// par.unwrap().asStr() == "/usr/local/bin"
p.pop();
// p.asStr() == "/usr/local/bin"
let joined: Path::PathBuf = p.join("rustc");
// joined.asStr() == "/usr/local/bin/rustc"
return 0;
}
namespace PathOwned filesystem path construction and normalization helpers.
PathBuf is string-backed and uses / as the separator on the currently
supported POSIX targets. Operations are lexical unless explicitly documented
otherwise; they do not query the filesystem.
Records
record PathBufOwned, mutable filesystem path.
Backed by a String — all mutation goes through String methods.
Drop frees the underlying String buffer.
data: Stringstatic create(s: str): PathBufCreates a path from a str literal.
Copies the bytes into a new owned String.
static fromString(s: &String): PathBufCreates a path by cloning an existing String.
static new(): PathBufCreates an empty path.
appendChildSegment(&self, normalized: &mut String, segment: &String, absolute: boolean): voidappendNormalizedSegment(&self, normalized: &mut String, segment: &String, absolute: boolean): voidappendParentSegment(&self, normalized: &mut String, segment: &String, absolute: boolean): voidasStr(&self): strBorrows the path as a str (const char*).
The returned pointer is valid for the lifetime of this PathBuf. Suitable for passing to libc functions that expect C strings.
clone(&self): PathBufReturns a deep copy of this PathBuf.
drop(&mut self): voidReleases the backing String buffer.
Called automatically when the PathBuf goes out of scope.
extension(&self): Option<String>Returns the extension of the file name, or NONE if there is
no file name or no extension.
The extension is the portion after the last . in the
file name. A leading dot (.bashrc, .gitignore) is not
treated as an extension separator — those files have no extension.
"photo.tar.gz"→SOME("gz")".bashrc"→NONE"Makefile"→NONE"archive.tar"→SOME("tar")
fileName(&self): Option<String>Returns the final component of the path, or NONE if the path
is empty or consists entirely of separators (i.e. root /).
Trailing separators are ignored:
"/usr/bin/"→SOME("bin")"/usr/bin"→SOME("bin")"/"→NONE""→NONE
isAbsolute(&self): booleanReturns true if the path starts with /.
isCurrentDirSegment(&self, segment: &String): booleanisEmpty(&self): booleanReturns true if the path contains no bytes.
isParentDirSegment(&self, segment: &String): booleanisRelative(&self): booleanReturns true when the path is not absolute.
isSegmentBoundary(&self, index: u64, len: u64): booleanisSeparatorAt(&self, index: u64): booleanjoin(&self, part: str): PathBufReturns a new PathBuf with part joined onto self.
Equivalent to cloning self and calling push(part).
lastSegmentIsParent(&self, normalized: &mut String): booleanlastSegmentStart(&self, value: &mut String): u64lastSepBefore(&self, limit: u64): u64Index of the last / within bytes 0..limit.
Returns limit (an impossible index) if no separator is found,
to avoid Option overhead in internal helpers.
normalize(&self): PathBufReturns a lexically normalized path without touching the filesystem.
parent(&self): Option<PathBuf>Returns the parent directory, or NONE if the path has no
parent (empty path, single component, or root /).
"/usr/local/bin"→SOME("/usr/local")"/usr/local/bin/"→SOME("/usr/local")"/foo"→SOME("/")"/"→NONE"foo"→NONE""→NONE
pop(&mut self): booleanRemoves the last component from the path.
Returns true if a component was removed, false if the path
has no parent (and was left unchanged).
After pop, the path equals what parent() would have returned.
popLastSegment(&self, normalized: &mut String, keepRoot: boolean): voidpush(&mut self, part: str): voidAppends a path component to this path.
POSIX join semantics:
- If
partstarts with/, it is absolute and replaces the entire path. - If
selfis empty,selfbecomespart. - If
selfalready ends with/,partis concatenated directly. - Otherwise a
/separator is inserted betweenselfandpart.
stringCharEquals(&self, value: &String, index: u64, expected: char): booleanstringMutCharEquals(&self, value: &mut String, index: u64, expected: char): booleanstripTrailingLen(&self): u64Effective length ignoring trailing /.
"/foo/bar/" → 8, "/" → 0, "" → 0.
toString(&self): StringReturns a clone of the inner String.
truncateNormalized(&self, normalized: &mut String, index: i64, keepRoot: boolean): voidFunctions
function __closure_thunk_0(__closure_env_0: *mut u8, b: u8): booleanConstants
const DOT_BYTE: u8const SEP: char