Skip to content

Simplify metadata/file-type handling in filesystem::primitives - #14356

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
alexcrichton:refactor-metadata
Sep 21, 2026
Merged

alexcrichton merged 1 commit into
bytecodealliance:mainfrom
alexcrichton:refactor-metadata

Conversation

@alexcrichton

@alexcrichton alexcrichton commented Sep 18, 2026

Copy link
Copy Markdown
Member

Avoid unwrapping structures into a shape only to re-wrap them later on into a WASI-defined shape. Instead remove various extension traits and shuffling of fields and instead use an enum for the definitions of Metadata and FileType which are either standard library types or rustix-based types. Accessors then delegate to the appropriate fields depending on how the data lies at rest.

The goal here is to remove layer of cognitive indirection where there's a platform-specific source of truth for the underlying data. Accessors where a specific type is requested or a particular operation is where the interpretation of the underlying data happens then.

Note that the reason that std::fs::Metadata alone isn't sufficient is that the Rust standard library doesn't bind functions like statat and there's no way to create a std::fs::Metadata externally from the standard library, hence the Unix-specific layer where metadata might be std::fs::Metadata and might be rustix::fs::Stat.

Avoid unwrapping structures into a shape only to re-wrap them later on
into a WASI-defined shape. Instead remove various extension traits and
shuffling of fields and instead use an `enum` for the definitions of
`Metadata` and `FileType` which are either standard library types or
rustix-based types. Accessors then delegate to the appropriate fields
depending on how the data lies at rest.

The goal here is to remove layer of cognitive indirection where there's
a platform-specific source of truth for the underlying data. Accessors
where a specific type is requested or a particular operation is where
the interpretation of the underlying data happens then.

Note that the reason that `std::fs::Metadata` alone isn't sufficient is
that the Rust standard library doesn't bind functions like `statat` and
there's no way to create a `std::fs::Metadata` externally from the
standard library, hence the Unix-specific layer where metadata might be
`std::fs::Metadata` and might be `rustix::fs::Stat`.
@alexcrichton
alexcrichton marked this pull request as ready for review September 18, 2026 22:27
@alexcrichton
alexcrichton requested a review from a team as a code owner September 18, 2026 22:27
@alexcrichton
alexcrichton requested review from dicej and removed request for a team September 18, 2026 22:27
@github-actions github-actions Bot added the wasi Issues pertaining to WASI label Sep 18, 2026
@alexcrichton
alexcrichton added this pull request to the merge queue Sep 21, 2026
Merged via the queue into bytecodealliance:main with commit 1a57ed4 Sep 21, 2026
54 checks passed
@alexcrichton
alexcrichton deleted the refactor-metadata branch September 21, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasi Issues pertaining to WASI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants