zerobus-sdk / rust
CLAUDE.md89 starsChanged 5 months agoApache-2.0View on GitHub
This is the core implementation. All other SDKs depend on it. See the root CLAUDE.md "Writing SDK client code — performance rules" for the cross-SDK rule. In Rust specifically: This is a Cargo workspace. The workspace root is rust/Cargo.toml. - builder/sdk_builder.rs — Typestate builder pattern for ZerobusSdk - errors.rs — ZerobusError enum with is_retryable() classification - headers_provider.rs — HeadersProvider trait + OAuth implementation - landing_zone.rs — Batches records before sending over gRPC - record_types.rs — EncodedRecord, ProtoMessage, JsonString; AvroRecord/AvroBytes and…
In this repository6 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- cpp/CLAUDE.mdCLAUDE.md
- go/CLAUDE.mdCLAUDE.md
- java/CLAUDE.mdCLAUDE.md
- python/CLAUDE.mdCLAUDE.md
- typescript/CLAUDE.mdCLAUDE.md
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 85
Every PR must update rust/NEXT_CHANGELOG.md under the appropriate section if it changes user-facing behavior.
- Very specific: line 86
Update rust/README.md if the change affects usage, setup, or API surface.
- Very specific: line 87
Add or update examples in rust/examples/ for new or modified APIs.
- Very specific: line 88
Add doc comments (///) for all new public items — these render on docs.rs.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust SDK
This is the core implementation. All other SDKs depend on it.
Client code patterns (examples, doc comments, generated code)
See the root CLAUDE.md "Writing SDK client code — performance rules" for the cross-SDK rule. In Rust specifically:
ingest_record_offset()/ingest_records_offset()return theOffsetIdonce the record is queued; the network round-trip is async. Never callwait_for_offset()after every ingest in a loop — it forces one server round-trip per record.- Correct pattern: ingest in a loop, then
flush()once (or periodically for unbounded streams). Or wait on only the last offset — the ack watermark is monotonic, so acking the last offset implies all prior are acked (wait_for_offset_internalwaits forlast_received_offset >= target). - Register an
ack_callbackfor async ack/error tracking instead of blocking. - Any new example,
///doc example, or test must show the loop-then-flush()pattern first; reserve per-recordwait_for_offset()for clearly-labeled low-volume cases.
Structure
rust/
├── sdk/ # Core SDK crate (databricks-zerobus-ingest-sdk)
├── ffi/ # C FFI crate — cbindgen generates zerobus.h (used by Go, Java)
├── jni/ # JNI crate — Java Native Interface bindings
├── examples/ # JSON, proto, Arrow Flight, and Avro ingestion examples
├── tests/ # Integration tests
└── tools/ # Schema generation CLIThis is a Cargo workspace. The workspace root is rust/Cargo.toml.
Key modules in sdk/src/
builder/sdk_builder.rs— Typestate builder pattern forZerobusSdkerrors.rs—ZerobusErrorenum withis_retryable()classificationheaders_provider.rs—HeadersProvidertrait + OAuth implementationlanding_zone.rs— Batches records before sending over gRPCrecord_types.rs—EncodedRecord,ProtoMessage,JsonString;AvroRecord/AvroBytesand thePreparedInputingest payload (Avro types behindavro)stream/arrow/— Arrow Flight ingestion, ACK rotation, connection, and recovery modules (behindarrow-flight); seestream/arrow/README.mdfor architecture and invariants
Build commands
Run from rust/:
make build/make build-release— Build SDKmake build-ffi— Build C FFI library (generateszerobus.h+ static/dynamic libs)make build-jni— Build JNI library for Javamake test— Run all workspace testsmake lint— Clippymake fmt— rustfmtmake check— fmt + lint
Breaking change rules
Any change to the Rust SDK's public API surface has cascading effects:
- Public types/traits (
pubitems inlib.rs) — used directly by Rust consumers. Removing or renaming is a breaking change. - FFI functions (
rust/ffi/) — changing a C function signature, struct layout, or removing a function breaks Go and Java. The headerzerobus.his auto-generated; always review the diff. - JNI exports (
rust/jni/) — changing native method signatures breaks Java. Must stay in sync withnativedeclarations in Java source. - PyO3 bindings (
python/rust/src/lib.rs) and NAPI-RS bindings (typescript/src/lib.rs) wrap the Rust SDK directly, so internal refactors can break them if module paths or type signatures change.
Safe changes: adding new public items, adding optional parameters with defaults, adding new enum variants (if non-exhaustive), adding fields to #[non_exhaustive] structs, adding feature-gated modules.
Adding methods to public traits (HeadersProvider, AckCallback, TlsConfig): always provide a default implementation. Users implement these traits externally; adding a method without a default breaks every external impl.
Deprecation path: mark with #[deprecated(since = "x.y.z", note = "Use X instead")], keep for at least one minor release, remove in next major.
Feature flags
arrow-flight— Arrow Flight support. Opt-in.avro— Avro record format (Beta). Off by default; requires Rust 1.88 (viaapache-avro0.22). Select with.avro(schema), then ingestAvroRecord(encoded against the writer schema) or pre-encodedAvroBytes. Ephemeral streams only; feature in development.internal-arrow-c-data— Unsupported wrapper-only C Data importer shared by the repository's native bindings. Disabled by default; external Rust users must not depend on its API stability.zeroparser— Zero-copy, single-pass protobuf parser driven byprost_types::DescriptorProto. Off by default; opt-in for downstream consumers. Source undersdk/src/zeroparser/; see its README for details.testing— Test utilities.
Error handling
ZerobusError variants are classified as retryable or non-retryable via is_retryable(). This distinction propagates through FFI (CResult.is_retryable) to all wrapper SDKs. When adding new error variants, always implement is_retryable() for them.
Async runtime
The SDK uses tokio. The FFI and JNI crates each manage their own tokio runtime instance — do not assume a runtime exists in the caller's context.
Changelog and documentation
- Every PR must update
rust/NEXT_CHANGELOG.mdunder the appropriate section if it changes user-facing behavior. - Update
rust/README.mdif the change affects usage, setup, or API surface. - Add or update examples in
rust/examples/for new or modified APIs. - Add doc comments (
///) for all new public items — these render on docs.rs.
Release
- Version source:
rust/sdk/Cargo.toml(version = "x.y.z"). - Tag:
rust/v<semver>→ triggersrelease-rust.yml→ publishes to crates.io. - The FFI crate (
rust/ffi/) has a separate version and tag (ffi/v*). An FFI release must happen before Go or Java can pick up Rust core changes, since they link the pre-built static library. - On version bump PR: move
NEXT_CHANGELOG.mdcontents toCHANGELOG.md, resetNEXT_CHANGELOG.mdwith the next version header. - Rust core version bumps may cascade: if the change affects FFI signatures or wrapper behavior, coordinate releases across affected SDKs.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

