corez: The Rust Shim That Makes std::io Vanish
A tiny no_std compatibility layer with a big job: keep Zcash code portable, safe, and independent of brittle ecosystem dependencies.
- corez preserves the mental model of std::io while swapping in a custom no_std implementation only when the target cannot use std.
- The crate is less about new I/O features than about owning a fragile compatibility boundary that Zcash does not want to outsource.
- Its design favors safe, predictable behavior over clever optimization, which is why no unsafe code is allowed anywhere in the crate.
- The repo treats governance as part of the system by documenting how AI agents should contribute, not just how humans should read the code.
corez is a shim, which is another way of saying it is designed to be missed. In a normal Rust project, you reach for std::io and move on. In Zcash’s world, that assumption has to survive servers, wallets, and constrained targets, so the crate keeps the familiar surface and swaps the implementation underneath.
The crate that disappears
The trick is simple to describe and easy to underestimate. When std is available, corez::io re-exports the standard library’s I/O module. When it is not, the crate supplies its own compatible module with the same mental model. Downstream code gets continuity instead of conditional chaos.
That matters because portability is not just a build concern. It is a product constraint. If one codebase has to work in a roomy runtime and a stripped-down environment, the abstraction boundary has to be stable enough that every consumer can keep speaking the same language.
Why Zcash needed its own I/O boundary
The immediate reason is practical. The ecosystem had already shown how fragile a shared dependency could be when core2 was yanked. corez is a response to that kind of volatility. Instead of depending on a compatibility crate whose future is outside Zcash’s control, the project owns the layer itself.
| Dimension | std mode | alloc no_std mode | pure no_std mode |
|---|---|---|---|
| API surface | Matches std::io closely | Matches the same core traits | Same traits, reduced runtime assumptions |
| Memory footprint | Delegated to std | Uses alloc for richer values | Leans on core-only data |
| Error richness | Standard library style | Can carry more context | Keeps error state lean |
| Target environments | Servers and desktops | Constrained but alloc-capable systems | Bare metal and the smallest targets |
| Safety model | Delegated to std internals | Safe Rust only | Safe Rust only |
The point is not that embedded targets are glamorous. The point is that a large privacy system needs a dependable low-level boundary. Once that boundary becomes somebody else’s package, your portability story inherits their maintenance risk.
How the shim works
The repo is deliberately mirrored. src/lib.rs is the dispatch point. Under #[cfg(feature = "std")], it re-exports std::io. Otherwise it exposes the crate’s own io module. That module is split into focused files for traits, errors, cursor logic, and implementations for slices and vectors.
#[cfg(feature = "std")]
pub use std::io;
#[cfg(not(feature = "std"))]
pub mod io;
This is the cleanest kind of conditional compilation. The call site does not need to know which reality it is in. The import stays the same, the trait names stay the same, and the implementation becomes a build-time decision instead of a downstream rewrite.
The safety trade-off: no unsafe, no drama
The crate forbids unsafe code outright, which changes the engineering style. That constraint removes the usual escape hatches for performance tricks, so the implementation leans into predictability: explicit error handling, careful cursor movement, and buffer writes that behave the same way every time.
That choice shows up in vec_write and related logic. If a cursor jumps past the current end of a vector, the gap is zero-filled instead of being left to undefined memory behavior. That makes the crate easier to reason about, easier to audit, and less dependent on optimizations that only matter in edge cases.
Why the error type matters
The error story is the balancing act. In alloc-capable builds, the crate can preserve richer error context. In leaner modes, it keeps the type compact and available without pulling in more machinery than the target can support. The API stays recognizable, but the storage strategy scales down cleanly.
That split is the real shape of the library. corez is not trying to be a better std. It is trying to be the smallest possible compatibility layer that still feels native to the code that depends on it.
The hidden governance story
There is one more surprising layer in the repo: AGENTS.md. The project is written not just for human contributors, but for AI coding agents too. That signals a team that sees contribution process as part of supply-chain quality, not an afterthought.
That matters here because the crate exists to reduce dependency risk. The same logic applies to people and tools. If the project wants to stay stable, it has to make its rules legible to the next agent that touches the code, whether that agent is a person or a model.
What corez is really buying
| Question | Answer |
|---|---|
| What does corez replace? | A brittle external compatibility layer. |
| What does it preserve? | The std::io mental model. |
| What does it add? | Control over feature-gated I/O behavior across target classes. |
| What does it avoid? | Unsafe shortcuts and hidden dependency risk. |
corez is invisible by design, but it is doing real architectural work. It lets one codebase keep its I/O vocabulary while changing its runtime assumptions underneath. For a system like Zcash, that is not just convenience. It is resilience.





