Union Pathpub

Source
:union(pub) Path
  | UnixPath (Vec U8)
  | WindowsPath (Vec U16)
Description

Path MUST be an internal union of OS-native byte representations. On Unix targets the UnixPath variant is populated with a sequence of 8-bit bytes; on Windows targets WindowsPath carries 16-bit code units. The concrete variant is selected per target at compile time. Paths are NOT guaranteed to be valid UTF-8.

Variants

| UnixPath Vec(U8)
| WindowsPath Vec(U16)

Implementations

impl Path

.components ( Path (Vec Component) )

.components — decompose the path into its left-to-right sequence of Component values. RootDir appears first (and only first) when the path is absolute. . / .. fragments surface as CurDir / ParentDir and are NOT resolved (that is .canonicalize's job).

.extension ( Path (Option PathSegment) )

.extension — file extension (portion of last segment after the final .). None if no ., . is first char, or no segments.

.file-name ( Path (Option PathSegment) )

.file-name — last segment as (Option PathSegment); None if the path has no segments.

.from-str ( Str Path )

.from-str — parse a Str into a Path. Leading / marks absolute; consecutive / collapse; trailing / is dropped. Qualified dispatch: "/home/user" (Path .from-str).

.is-absolute ( Path Bool )

.is-absolute — true iff the path starts with /.

.is-relative ( Path Bool )

.is-relativetrue iff the path does not start with /.

.join ( Path Str Path )

.join — append a segment string. The string MUST NOT contain /.

.parent ( Path (Option Path) )

.parent — path with last segment removed, or None if already at root. Single-segment paths yield / (absolute) or . (relative).

.segments ( Path (Vec PathSegment) )

.segments — the sequence of PathSegment values after parsing, excluding any leading root marker.

.stem ( Path (Option PathSegment) )

.stem — last segment with its extension stripped. None iff the path has no segments.

.to-str ( Path (Result Str Str) )

.to-str — render a Path back to a Str. Returns Err when the underlying bytes are not valid UTF-8.

.to-string-lossy ( Path Str )

.to-string-lossy — always-successful Str rendering; invalid UTF-8 is replaced with U+FFFD.