blake3::hash already has a bridge-compatible shape: bytes in, digest bytes out.
blake3 produces a BLAKE3 digest, not SHA-1 or SHA-256. If you need those algorithms, bind a crate such as
sha1 or sha2 the same way.Why this shape
Rust interop is source-level Cargo integration. Sifr does notdlopen a Rust crate or invent a C ABI. You declare a Sifr function whose target is a Rust item, and the compiler checks that the Rust signature matches before codegen.
Three rules drive the blake3 declaration:
- Compatible signatures can bind directly. Prefer
@rust(blake3.hash, ...)when the public Rust function already maps to Sifr types. - Panic policy is part of the contract. Recoverable builds must not let a Rust panic unwind through Sifr user code. Choose
trusted_no_paniconly with trust evidence, ormap_error(...)to convert panics into a declared error. - Stub bodies are intentional. Package-authored declarations use
.... Behavior comes from validated Rust interop metadata, not from a Sifr function body.
src/bridges instead. blake3’s one-shot hash does not need that.
Package setup
Add the crate and declare Rust interop policy:Cargo.toml
sifr.toml
sifr bridge check so decorator parsing, target resolution, and panic policy match ordinary sifr check.
Declare and call
blake3.hash resolves through Cargo metadata to the blake3 dependency. The return type keeps failure visible: either digest bytes or a checked error channel that includes panic mapping.
If you have audited evidence that the target cannot panic, you can instead declare panic=trusted_no_panic and list blake3.hash under [trust].rust-no-panic. Prefer map_error until that evidence exists.
When to switch to a bridge
Stay on a direct binding for one-shot hashing. Move to a bridge when you need output shaping, such as hex encoding:src/bridges/hash.rs
Next steps
- Full contract catalog: Rust Interop
- Async HTTP with a bridge: reqwest
- Trust and Cargo policy: Package Manifest
