@rust-migration

Plan, implement, or audit a port to Rust. Compare behavior with the original and verify compatibility, shipped artifacts, performance, and rollback.

Rust Migration

When to Use

  • Assess whether a module, library, CLI, or service should move to Rust.
  • Port existing code while keeping its callers, file formats, or runtime integrations working.
  • Review an existing Rust port for behavior drift, release compatibility, or cutover readiness.

Prerequisites

Identify the original revision, current callers, supported environments, and the reason for the port. For execution, use the project's documented build and test entry points, toolchains, fixtures, and an authorized local checkout. For static assessment, record which behavior remains unverified when the baseline cannot run.

Migration Workflow

Capture the compatibility contract

  1. Pin the original revision and record its build, invocation, dependencies, and relevant configuration. Run the existing tests and capture outputs from representative inputs through the public entry point. Start with checked-in, synthetic, or approved redacted fixtures.
  2. Record what callers observe, including results, error types or exit codes, ordering, encodings, and side effects. Check known production edge cases and old data formats. List intended behavior changes with their expected outcomes so the differential test can distinguish them from regressions.
  3. Define success against the reason for moving. If performance drives the work, profile the current application before picking a boundary and agree on the workload and metric. If supportability or safety drives it, identify the dependency or invariant that must change.

Port one boundary at a time

  • Start with a slice that can be exercised independently. Choose a library binding when preserving in-process callers matters, a subprocess when a stable protocol and process isolation fit, or a service replacement when deployment and data compatibility can be verified. Keep conversion at the boundary and reuse caller-facing tests.
  • Make language assumptions explicit during translation. Check numeric widths, overflow and rounding, missing values, string encodings, ordering, and concurrency semantics where the contract depends on them. Use fallible conversions and map expected failures to the existing caller-facing errors.
  • For native bindings, document who owns each buffer or handle, who frees it, which threads may use it, and what happens on failure. Check layout, lifetimes, allocation and deallocation across runtimes, and unwinding rules. Prefer safe Rust and keep any necessary unsafe behind a small interface with documented invariants.

Check behavior and the shipped artifact

  • Run the same fixtures through both revisions. Compare exact values for discrete fields and protocol details, and define the comparison rule and tolerances for approximate values. Handle missing masks, NaNs, and infinities explicitly. Include empty, boundary, malformed, and representative cases. Reproduce mismatches against the pinned original before changing the port or the fixture.
  • Test through the normal caller with the actual build or package. For an optional native backend, explicitly exercise both implementations and confirm the selected backend and version so fallback or a stale installation cannot hide a failure. Check the declared minimum supported Rust version, feature combinations, and target or host runtime versions the project supports.
  • For performance claims, compare representative release builds on the same machine with the same inputs and workload conditions. Measure the changed code and the normal end-to-end path, including boundary conversions, startup, and I/O where relevant. Report the metric, run count, variation, and workload. Use profiles to decide whether an additional optimization is warranted.

Verify cutover and rollback when applicable

  • Keep the previous path selectable while compatibility is being established. Test fallback explicitly and ensure retries cannot repeat partial writes. Compare side effects in isolated environments or use a comparison path that cannot write.
  • For stateful systems, verify coexistence and whether the old version can read new writes. Test rollback on a representative copy, including persisted state. If reversing a data change requires restore or replay, document that procedure and its limits before cutover.

Audit Handoff

Identify the exact original and Rust revisions and artifacts checked. For each finding, give the affected entry point, a reproduction, expected and observed behavior, and its impact on callers. Include the smallest corrective step and the evidence needed to verify it. State the platforms, inputs, and behaviors still awaiting verification.

Example

Port the timestamp bucketing helper to Rust and preserve the signed timestamp behavior.

Use the original implementation to generate a fixture for zero, negative timestamps, bucket boundaries, and integer limits. The example catches a direct translation that compiles but moves pre-epoch timestamps into the wrong bucket. Run the differential test.

Limitations

  • Parity applies to the tested inputs, callers, builds, and environments. Test artifacts on their supported hosts before claiming deployment compatibility.
  • A speedup in a kernel benchmark applies to that measured kernel. End-to-end performance requires measurements through the real caller.

Safety and Side Effects

Audit through inspection and authorized tests in an isolated checkout. Apply source changes only within the requested implementation scope. Builds can execute project code through build scripts, macros, or test hooks and can download dependencies. Inspect those entry points before building unfamiliar code. Use approved fixtures locally and obtain authorization for production traffic, data writes, publishing, or cutover.