Subject
anstyle-wincon bridges ANSI styling (the anstyle crate's color types) and the Windows console-attribute API. On non-Windows platforms it falls through to emit ANSI escape sequences; on Windows it calls GetConsoleScreenBufferInfo / SetConsoleTextAttribute via windows-sys to flip console foreground/background attributes around a write, restoring the initial colors afterward.
Methodology
The published crate (anstyle-wincon-3.0.11.crate) was unpacked. All four source files (src/lib.rs 25 lines, src/ansi.rs 25 lines, src/stream.rs 163 lines, src/windows.rs 260 lines) and both example binaries were read in full. The crate lives at crates/anstyle-wincon/ inside the rust-cli/anstyle.git workspace; diff -qr against the upstream Git checkout at commit 368a87194743 showed only cargo-generated meta differences. Source was greped for unsafe, extern, process::, std::net, std::fs, env::. The two Win32 FFI blocks in src/windows.rs were inspected in detail for invariant discipline. The colocated to_from_nibble unit test was read.
Tools used: openvet (workspace creation, claim/finding management), GNU diff 2.8, grep 2.6.
Results
The published source matches upstream byte-for-byte. The crate ships no binary artefacts (justifying has-binaries), no build.rs (build = false, justifying has-build-exec), and no install hooks (justifying has-install-exec).
There are exactly two unsafe blocks, both inside src/windows.rs and only compiled under cfg(windows): get_screen_buffer_info (lines 127-141) and set_console_text_attributes (lines 148-160). Each block does only what is strictly necessary — null-check the raw handle, cast it to HANDLE, zero-initialize the CONSOLE_SCREEN_BUFFER_INFO out-parameter, call exactly one windows-sys function, and convert the return code to a Result. The invariants are obvious and minimal (justifying uses-unsafe, unsafe-safe, unsafe-minimal). Neither block carries a SAFETY comment (FINDING-1), justifying unsafe-documented = false. The Win32 calls themselves are not exercised by any in-tree test (justifying unsafe-tested = false); the colocated to_from_nibble unit test only covers the pure-Rust attribute-nibble conversion.
The crate accepts std::fs::File and other write sinks as targets for colored writes; it never opens, deletes, or reads files itself, so the filesystem usage surface is "writes to caller-provided handles" (justifying uses-filesystem = true and filesystem-safe = true). No std::process, std::net, or env:: usage was found, justifying uses-network, uses-exec, uses-environment, uses-crypto, uses-jit, uses-interpreter, uses-concurrency. The crate does not itself implement cryptography (justifying impl-crypto), parsers (justifying impl-parser), interpreters (justifying impl-interpreter), JITs (justifying impl-jit), protocols (justifying impl-protocol), data structures (justifying impl-datastructure), non-trivial algorithms (justifying impl-algorithm), or concurrency primitives (justifying impl-concurrency) — the nibble conversion table is the only logic worth flagging, and its design is direct table-lookup.
In-source unit tests cover the nibble roundtrip (justifying has-unit-tests). No integration, fuzz, or property tests are shipped (justifying has-integration-tests, has-fuzz-tests, has-property-tests).
Two low-severity quality findings were recorded:
- FINDING-1: the two Win32 unsafe blocks lack SAFETY comments.
- FINDING-2:
include = [...] lists build.rs, which is absent.
The crate is benign — small, well-bounded, and the only privileged operations are documented Win32 calls inside cfg(windows) blocks — justifying is-benign.
Conclusion
anstyle-wincon 3.0.11 is a small, focused Windows console-attribute bridge with two narrowly-scoped FFI blocks and one fall-through ANSI path. Both findings are documentation/housekeeping nits. The package is suitable for use.