Module path

path

Cross-platform filesystem path manipulation.

Types

PathError enum
PathError

Path parsing error variants.

Variants

VariantFieldsDescription
EmptyPath

The path string was empty.

InvalidPathmessage: String

The path string was malformed.

Path object
Path

Filesystem path with segment-based operations. Paths are normalized on construction: . segments are removed, .. pops the parent.

Fields

NameTypeDescription
_segmentsArrayList(String)
_is_absolutebool

Trait Implementations

impl(Path, ...)
new : (Path) fn(path_str : String) -> Path

Create a new path from a string. Normalizes separators and resolves ./...

Parameters

NameTypeNotes
path_strString

Returns: Path

from_cstr : (Path) fn(cstr : *(u8)) -> Path

Create a path from a C string pointer.

Parameters

NameTypeNotes
cstr*(u8)

Returns: Path

join : (Path) fn(self : Path, other : Path) -> Path

Join this path with another. If other is absolute, returns other.

Parameters

NameTypeNotes
selfPath
otherPath

Returns: Path

parent : (Path) fn(self : Path) -> Option(Path)

Get the parent directory path, or .None if there are no segments.

Parameters

NameTypeNotes
selfPath

Returns: Option(Path)

file_name : (Path) fn(self : Path) -> Option(String)

Get the last path segment (filename), or .None for empty paths.

Parameters

NameTypeNotes
selfPath

Returns: Option(String)

file_stem : (Path) fn(self : Path) -> Option(String)

Get the filename without its extension, or .None for empty paths.

Parameters

NameTypeNotes
selfPath

Returns: Option(String)

extension : (Path) fn(self : Path) -> Option(String)

Get the file extension (without the dot), or .None if there is none.

Parameters

NameTypeNotes
selfPath

Returns: Option(String)

with_extension : (Path) fn(self : Path, ext : String) -> Path

Return a new path with the extension replaced by ext.

Parameters

NameTypeNotes
selfPath
extString

Returns: Path

with_file_name : (Path) fn(self : Path, name : String) -> Path

Return a new path with the last segment replaced by name.

Parameters

NameTypeNotes
selfPath
nameString

Returns: Path

starts_with : (Path) fn(self : Path, base : Path) -> bool

Check if this path starts with the given base path (segment-wise).

Parameters

NameTypeNotes
selfPath
basePath

Returns: bool

ends_with : (Path) fn(self : Path, suffix : Path) -> bool

Check if this path ends with the given suffix path (segment-wise).

Parameters

NameTypeNotes
selfPath
suffixPath

Returns: bool

components : (Path) fn(self : Path) -> ArrayList(String)

Get all path components as a list. Absolute paths start with "/".

Parameters

NameTypeNotes
selfPath

Returns: ArrayList(String)

is_absolute : (Path) fn(self : Path) -> bool

Check if the path is absolute.

Parameters

NameTypeNotes
selfPath

Returns: bool

is_relative : (Path) fn(self : Path) -> bool

Check if the path is relative (not absolute).

Parameters

NameTypeNotes
selfPath

Returns: bool

impl(Path, ToString(...))
to_string : (self -> { segments := self._segments; sep := String.from("/"); result := String.new(); // Check if first segment is a Windows drive letter (e.g., "C:") has_drive_letter := cond( (segments.len() > usize(0)) => { first_seg_opt := segments.get(usize(0)); match(first_seg_opt, .Some(first_seg) => // Check if it's a drive letter like "C:" cond( (first_seg.len() == usize(2)) => { b0_opt := first_seg.as_bytes().get(usize(0)); b1_opt := first_seg.as_bytes().get(usize(1)); match(b0_opt, .Some(b0) => match(b1_opt, .Some(b1) => { is_letter := (((b0 >= u8(65)) && (b0 <= u8(90))) || ((b0 >= u8(97)) && (b0 <= u8(122)))); is_colon := (b1 == u8(58)); (is_letter && is_colon) }, .None => false ), .None => false ) }, true => false ), .None => false ) }, true => false ); // For Unix absolute paths, prepend / // For Windows paths with drive letter, don't prepend / cond( (self._is_absolute && !has_drive_letter) => { result = result.concat(sep); }, true => () ); i := usize(0); segments_len := segments.len(); while ((i < segments_len)), (i = (i + usize(1))), { seg := segments.get(i); match(seg, .Some(s) => { result = result.concat(s); cond( ((i < (segments_len - usize(1)))) => { result = result.concat(sep); }, true => () ); }, .None => () ); }; return result; })
impl(Path, Eq(Path))

Constants

PATH_SEPARATOR constant u8

Platform-specific path separator: '/' on Unix, '\\' on Windows.

Value: 47

PATH_DELIMITER constant u8

Platform-specific path list delimiter: ':' on Unix, ';' on Windows.

Value: 58