/rewrite-rs-skills:port-from-gofrom rewrite-rs-skills
Maps Go constructs to Rust equivalents — goroutines to tasks, interfaces to traits, errors to Result — and flags value-semantics traps like zero values, integer wraparound, slice aliasing, and nil. Use when porting Go services or CLIs to Rust.
Ships in rewrite-rs-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill maps Go semantics and owns the Go boundary; process is
/port-to-rust. Go syntax maps almost mechanically and the runtime
model does not, so the easy-looking translation is where the port
goes wrong.
/port-to-rust names three end states; Go ports land on A — no
bindings — far more often than Python or JavaScript ports do,
because the cost of the alternative is cgo and a Go system almost
always already has a boundary to strangle at. A default, not a
rule: B is real when the deliverable is a Go-importable package;
C when a leaf function moves before its callers.
Go has no cheap in-process FFI: cgo works in both directions but is
slow at the call, awkward in the build, and drags the Go runtime
along. For most Go ports the right seam is one the system already
has — an HTTP route, a gRPC service, a subcommand, a queue consumer
— and the strangler strategy in /port-to-rust is the default, not
in-place FFI; mechanics and the cgo escape hatch are in
BOUNDARY.md.
| Trap | What actually differs |
|---|---|
| Integer overflow | Go wraps on overflow, always. Rust panics in debug and wraps in release. Any arithmetic that could overflow needs an explicit choice — wrapping_add to reproduce Go, or checked arithmetic plus a decision about what the new error path does |
| Zero values | Every Go type is constructible with all fields zeroed, and code relies on it — an empty struct is a valid, meaningful value. Rust has no implicit zero value, so each such site becomes either a Default impl (reproducing the behaviour) or a constructor that refuses (changing it). Reproducing is parity; refusing is an improvement, and improvements wait |
nil is several things | A nil pointer, a nil slice (which appends fine and has length zero), a nil map (which reads fine and panics on write), and a nil interface holding a typed nil. Option<T> covers the first; the rest are behaviour, not absence, and mapping them all to Option produces subtle breakage |
| Slice aliasing | Go slices share a backing array, so a subslice mutation is visible through the original and append may or may not copy depending on capacity. Rust makes this impossible, which is the point — but if the source relied on the aliasing, the port must reproduce the observable effect deliberately, and if it relied on it accidentally, that is a bug found by the port and recorded |
| Error strings as contract | Go code branches on err.Error() text and on sentinel values via errors.Is. A port that redesigns the error taxonomy breaks callers that were matching on strings. Map the sentinel set first, then design — /rust-errors |
MAPPING.md holds the full table; a row is a starting point, not a
rewrite rule. The syntax maps easily and the runtime model does not
— the easy-looking rows are the ones to read twice.
A Go interface is satisfied by shape, so the port finds the
implementers and writes impl Trait for Type for each: an interface
with one implementer is a struct, not a trait, and one used purely
for test substitution maps to a generic parameter, not dyn.
Go table-driven tests port almost directly and are characterization
input; benchmarks are not parity evidence. Go suites are thin on
concurrent interleaving, where the port changes behaviour — a race
the GC and scheduler hid is still a race. Harness shapes are
/rust-testing.
go f() maps to tokio::spawn or a thread depending on whether the
work is IO-bound or CPU-bound — per call site, not per codebase.
Channels map to tokio::sync::mpsc (or crossbeam for threads),
select to tokio::select!, sync.WaitGroup to collected
JoinHandles. Three differences worth stating plainly: a Rust
future is lazy until polled while a goroutine starts immediately;
tokio::select! cancels the losing branches, so anything holding
state across it needs cancellation safety (/async-rust); and an
unbounded Go channel pattern usually wants a bounded Rust channel,
which introduces backpressure the source did not have — a contract
change if it can block a caller.
Cancellation becomes a CancellationToken or a shutdown channel
selected on; deadlines become tokio::time::timeout; request-scoped
values threaded through context become explicit parameters or a
request struct, which is usually a readability win and always a
diff-size problem — decide before starting, not per function.
Both sides:
cargo test --all-features
cargo clippy --all-targets --all-features # add -- -D warnings only if the target repo has no lint config
go test ./... # the source still passes while both implementations run
go vet ./...
Then the differential run with its denominator, and the Go-specific corpus requirement: at least one case per trap — arithmetic at the wraparound boundary, a zero-valued struct, a nil map or nil slice, a subslice that was mutated, and a caller that matched on an error sentinel. Add the concurrency check: run the Rust side under load with more than one worker, because a single-threaded differential run proves nothing about the part of the port that changed most.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
28 skills in this plugin
/async-rustWrite correct async Rust — runtime choice, Send and Sync bounds, cancellation safety, blocking work inside async contexts, and shared state across tasks. Use when writing or reviewing async code, when a future is held across an await point, when the user hits a Send bound error on a spawned task, when a runtime stalls or deadlocks, or when the user asks about tokio, select!, or spawn_blocking./idiomatic-rustWrite Rust that reads like Rust — iterator pipelines over index loops, From/Into over ad-hoc converters, derives over hand-written impls, newtypes over bare primitives. Use when writing new Rust, when reviewing Rust that reads like a translation from another language, when reaching for a classic design pattern (strategy, command, visitor) or a try/finally cleanup in Rust, when naming a constructor, accessor, iterator, or error type, or when the user asks how to make Rust code more idiomatic or less repetitive./ownership-not-cloneUse ownership and borrowing instead of reaching for clone, Rc, RefCell, or Arc<Mutex<_>> to silence the borrow checker. Every clone must be explainable. Use when code clones to make an error go away, when a borrow-checker fight is being resolved by copying data, when reviewing Rust dense with .clone() or Rc<RefCell<_>>, or when the user asks whether a clone is necessary./port-from-cPort C into Rust — recovering the ownership, lifetime, nullability, and length that C never recorded, mapping pointers to references and slices, tag-plus-union to enums, return codes and errno to Result, and linking Rust into the existing build with bindgen and cbindgen. Use when porting, rewriting, or migrating C, a C library, firmware, or a C application into Rust, when replacing C modules one at a time behind the existing build, or when the user asks how a C construct such as malloc, a char pointer, a union, or a preprocessor macro translates to Rust./port-from-cppPort C++ into Rust — RAII and smart pointers onto ownership, templates onto generics and traits, exceptions onto Result, the STL onto Rust collections, and the traps (move semantics, implicit conversions, undefined behaviour, iterator invalidation). Use when porting, rewriting, or migrating C++, a C++ library, or a C++ application into Rust, when replacing a C++ module with Rust behind the existing build, or when the user asks how a C++ construct such as unique_ptr, shared_ptr, a template, or an STL container translates to Rust./port-from-javaPort Java into Rust — class hierarchies onto enums and composition, exceptions onto Result, collections and streams onto Rust equivalents, and the traps (UTF-16 strings, silent integer wraparound, null, equals/hashCode contracts). Use when porting, rewriting, or migrating Java, a JVM service, a Spring or Jakarta application, or a Java library into Rust, when replacing a JVM component with a Rust one behind the same interface, or when the user asks how a Java construct translates to Rust.npx claudepluginhub rewrite-rs/skills --plugin rewrite-rs-skillsOther plugins' skills for the same job