Subject
anstyle-query is a thin terminal-capability query crate. It exposes free functions that consult well-known environment variables to decide whether a program should emit ANSI color codes (clicolor, clicolor_force, no_color, term_supports_color, term_supports_ansi_color, truecolor, is_ci) and a Windows-specific helper (windows::enable_ansi_colors, windows::enable_virtual_terminal_processing) that calls SetConsoleMode to turn on ENABLE_VIRTUAL_TERMINAL_PROCESSING on stdout/stderr. The only runtime dependency is windows-sys (target-gated to cfg(windows)).
Methodology
The published crate contents were compared against the upstream Git repository at the commit recorded in .cargo_vcs_info.json using diff -r. The crate is published from crates/anstyle-query of the rust-cli/anstyle workspace; the symlinked vcs/ directory points at that subdirectory. The two source files (src/lib.rs, src/windows.rs, 242 lines combined) were read in full, the single unsafe block was checked against its Win32 FFI invariants, and the example was inspected.
Results
The comparison between the published crate contents and the upstream Git repository shows that the source files, README.md, and the LICENSE-* files match byte-for-byte. Manifest differences are limited to cargo's standard Cargo.toml normalisation plus the addition of .cargo_vcs_info.json, Cargo.lock, and the preserved Cargo.toml.orig. The upstream CHANGELOG.md is not included in the published crate per the include glob. The upstream repository does not contain a tests/ directory for this crate (FINDING-2).
The crate ships no binary artefacts, no build.rs, no proc macros, and no install hooks, justifying has-binaries, has-build-exec, and has-install-exec. The published source has 3 inline #[test] functions in src/lib.rs:141-159 covering the non_empty helper, justifying has-unit-tests; there are no integration tests, no fuzz harness, and no property tests, justifying has-integration-tests, has-fuzz-tests, and has-property-tests. The package contains no malicious code or deliberately harmful behaviour, justifying is-benign.
The codebase was reviewed for cryptographic libraries (none), network I/O (none), file I/O (none — the Windows helper operates on already-open stdio handles, not the filesystem), process execution (none — SetConsoleMode is a syscall on an already-open console handle, not spawning a process), interpreters or JIT (none), and concurrency primitives (none). This justifies uses-crypto, uses-network, uses-filesystem, uses-exec, uses-jit, uses-interpreter, uses-concurrency, impl-crypto, impl-parser, impl-interpreter, impl-jit, impl-protocol, impl-datastructure, impl-algorithm, and impl-concurrency.
The crate consults environment variables (justifying uses-environment). The variables are limited to a closed list of documented terminal-capability conventions: CLICOLOR, CLICOLOR_FORCE, NO_COLOR, TERM, COLORTERM, and CI. The crate never writes to the environment, never enumerates std::env::vars(), and never sends data anywhere — it only matches the value against documented strings ("0", "dumb", "cygwin", "truecolor", "24bit"). This justifies environment-safe.
There is exactly one unsafe block in the crate, at src/windows.rs:13-33, gated by #[cfg(windows)]. It calls windows_sys::Win32::System::Console::GetConsoleMode and SetConsoleMode on a HANDLE obtained from std::io::stdout().as_raw_handle() / stderr().as_raw_handle(). The handle is null-checked before use, both syscalls have their error returns translated to io::Error, and the windows-sys declarations carry the correct ABI for the target. The block lacks a per-block // SAFETY: comment (FINDING-1) but the FFI is small and the soundness argument is direct. The block is not exercised by the published unit tests (FINDING-2), so unsafe-tested is left unasserted; unsafe-safe and unsafe-minimal are asserted on the strength of the small, well-bounded surface. Justifies uses-unsafe.
Two low-severity quality findings were recorded: FINDING-1 for the missing per-block SAFETY comment on the Windows FFI, and FINDING-2 for the limited test coverage (the upstream repository does not ship a wider test suite for this crate either, so this is informational).
Conclusion
anstyle-query is a tiny, focused capability-detection crate. The audit found no security, safety, or correctness defects. The single unsafe block performs a standard Win32 console-mode configuration. The package is benign and safe to use.