Skip to content

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

Open
alexcrichton wants to merge 1 commit into
bytecodealliance:mainfrom
alexcrichton:refactor-metadata
Open

alexcrichton wants to merge 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
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.

1 participant