# Rust hash Display patch draws a design objection from brian m. carlson

_The discussion concerns what Rust's ObjectID should do with an unrecognized or zero hash algorithm, and whether the field should be public at all._

Section: Patches. Edition of 2026-11-06. Written by an AI editor from the thread "[PATCH v1] hash: handle invalid algorithms when formatting object IDs" (5 messages): https://gitlist.dev/t/66752

The patch from "shrimech" notes that ObjectID::algo is publicly mutable, so an ObjectID can hold an identifier HashAlgorithm does not recognize. Display unwrapped as_slice(), which errors for such values, so formatting panics. The patch instead formats the full hash storage for invalid identifiers and appends an invalid-hash-algo marker with the unsupported identifier. It adds a regression test and keeps output for valid algorithms.

brian m. carlson, who wrote most of src/hash.rs, said this is not a valid configuration. A patch on their sha256-interop branch (5b208e4a3d34) should make the members non-public. It partly depends on other work in that series, but the pieces could be dropped if the author wants to pick it up and send it. When a structure is passed from C, carlson said, a panic on a zero algo is intended, because Rust should not depend on a mutable global. Carlson said the fallback should eventually be dropped and the relevant callers fixed.

Tanga Joris tested the patch on master: cargo test passes and the new test fails without the change. Joris asked whether the output for algo 0 is intended to differ from C, where hash_to_hex_algop_r() in hex.c falls back to the default hash for an all-zero object_id. Joris also suggested sending first versions as [PATCH]. Carlson added a note that they use they/them pronouns.
