Skip to content

Expose windows file attributes. - #427

Merged
Byron merged 3 commits into
Byron:mainfrom
raldone01:feat/windows_file_attributes
Nov 3, 2026
Merged

Byron merged 3 commits into
Byron:mainfrom
raldone01:feat/windows_file_attributes

Conversation

@raldone01

@raldone01 raldone01 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor
  • Expose windows file attributes.
  • Mirror std FileType Debug impl.

Also cool to see #[must_use] littered in a code base for once. I think rust should really make all types must use by default. Hopefully they will do it in a future edition. I think it should be opt-out rather than opt-in. I mean rust already has the very nice _ and it makes functions that return something obvious.

@raldone01
raldone01 force-pushed the feat/windows_file_attributes branch from d92b887 to 900db78 Compare November 2, 2026 14:31
Mirror std `FileType` `Debug` impl.
@raldone01
raldone01 force-pushed the feat/windows_file_attributes branch from 900db78 to d41814e Compare November 2, 2026 14:51
Byron and others added 2 commits November 3, 2026 06:55
<!-- agent -->
### Added

- Introduce `FileAttributes` with named, combinable flags and readable debug output.
- Add an opt-in `unstable` feature for the Windows attribute API, keeping it available automatically to unit tests.

### Changed

- Use concise tuple-style `FileType` debug output on macOS and Windows, such as `FileType(Directory)`.
- Document query-specific attribute semantics without assuming directory enumeration returns a strict subset of flags.

Assisted-by: GPT 6.0 Astra
Co-authored-by: GPT 6.0 Astra <codex@openai.com>
@Byron
Byron force-pushed the feat/windows_file_attributes branch from 8dae267 to ca235bd Compare November 3, 2026 06:00
@Byron
Byron merged commit d682da7 into Byron:main Nov 3, 2026
4 checks passed
@raldone01

Copy link
Copy Markdown
Contributor Author

@Byron thanks for merging. Btw why did you change the Debug impls? I copied them exactly from the rust std lib.

@Byron

Byron commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Yes, they are changed to be more concise.

@raldone01

Copy link
Copy Markdown
Contributor Author

It's fine.

#[stable(feature = "std_debug", since = "1.16.0")]
impl fmt::Debug for FileType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("FileType")
            .field("is_file", &self.is_file())
            .field("is_dir", &self.is_dir())
            .field("is_symlink", &self.is_symlink())
            .finish_non_exhaustive()
    }
}

I was also surprised rust picked the above for the std Debug impl.

@raldone01

Copy link
Copy Markdown
Contributor Author

Also I am curious why gate it behind unstable? Rust std has stable support for file_attributes on windows: https://doc.rust-lang.org/std/os/windows/fs/trait.MetadataExt.html#tymethod.file_attributes

Will this become stable or is it just because it is a feature that is platform specific? I am pretty sure windows might add flags but they will never remove/change existing ones.

@Byron

Byron commented Nov 3, 2026

Copy link
Copy Markdown
Owner

The method is unstable because I don't want to commit to it forever.
And yes, on Windows with junctions there might dir symlinks and file symlinks, so the Rust version of the debug impl is probably less degenerating. I'd recommend keeping the current version, and instead go with something like FileType(LINK|DIR) if it's a dir link on Windows. Feel free to submit a PR for that.

@raldone01

Copy link
Copy Markdown
Contributor Author

Makes sense. I think all changes work fine for my use case. Thanks for cutting a release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants