Developing the Rust SDK

This page gives the build, test and lint tasks for developers of the SDK itself. Pipeline authors do not need these tasks. See the SDK README.

Run builds and tests through Gradle, like the rest of the Beam repository. The Gradle tasks call cargo, so a cargo command gives the same result:

# Core Lifecycle Tasks
./gradlew :sdks:rust:build             # Compile all crates in workspace
./gradlew :sdks:rust:check             # Run formatting checks and clippy linter
./gradlew :sdks:rust:test              # Run all tests (or -Ppkg=apache-beam-model)
./gradlew :sdks:rust:fmt               # Apply code formatting (cargo fmt)
./gradlew :sdks:rust:clean             # Remove the cargo target directory

One way

Every public API change follows these rules:

  • No aliases or compatibility shims. A rename removes the old name. The same change updates every caller, example and doc.
  • One public path per item. Pipeline items are in their module (transforms, transforms::sdf, windowing, coders, ...). Runner and harness plumbing (BundleHandler, ElementSink, HandlerContext, ...) is only in beam::internals. The preludes are the only additional path.
  • Fluent methods mirror core transforms. Each method is the snake_case name of exactly one core transform (.group_by_key → GroupByKey). It adds no semantics. Documented exception: with_side_singleton / with_side_iter / with_side_map. Each of these is a ParDo with one side input.
  • Fluent covers common cases. For advanced configuration, use .apply(name, Transform::new(..)), which also chains. Do not add fluent variants for advanced configuration.
  • Construction. Build transforms with new(required..) and .with_*() builders. The name of a transform is given at apply(name, transform), not to the constructor. Value types (e.g. FixedWindows::of) are exempt.
  • Errors. User hooks (DoFn, CombineFn, state, timers) return beam::Result.
  • Prelude. beam::prelude contains only the items that a typical pipeline author uses.

Comments and documentation

Comments and rustdoc follow the writing rules of ASD-STE100 Simplified Technical English. Beam, Rust and protocol terms are permitted technical names.

  • Short sentences. At most 20 words for an instruction and 25 words for a description. One topic per sentence.
  • Active voice. Write instructions in the imperative: “Call finish before drop”, “Do not share the sink”.
  • One word, one meaning. Use the same term for the same thing in all files.
  • Say what the code cannot. Write a comment for a constraint, a contract or a reason that is not clear from the code. Do not repeat what the code does.
  • No numbered steps. If the order is important, say so in words or split the code into functions.
  • No history. Do not write “used to”, “now”, “previously”, “no longer” or “Regression:”. Write the rule that is true for the current code. A test comment states the behavior that the test checks.
  • This SDK only. Do not compare with other SDKs (“like Java”, “same as Go”, “the equivalent of”). Name another SDK only when the behavior depends on it: a cross-language transform that the code calls, or a wire format, URN or protocol rule that other SDKs must decode. Comparisons between SDKs go in DESIGN.md.
  • Plain words. Use the simplest word that is correct. Do not use: thus, hence, therefore, obey, ensure, utilize, leverage, facilitate, via, prior to, subsequent, terminate, approximately, sufficient, robust, seamless, comprehensive, crucial, essential, simply, merely, basically, actually, effectively, notably, furthermore, moreover, additionally, “in order to”, “note that”, “stem from”. Use so, follow, make sure, use, help, through, before, then, stop, about, enough, also, to.
  • Short. A comment is shorter than the code it explains. Fill lines to about 90 columns: one short sentence does not need its own line.
  • Rustdoc. Start with a one-line summary. Do not repeat the item name (“Returns the key.” on fn key). Add # Errors, # Panics or # Safety only when the condition is not clear from the signature and the summary.