agentleFS
kabudukabudu/engineering-agent-skills/skills/rust-port/SKILL.md

rust-port

Skill3 starsChanged 13 days agoMITView on GitHub

Port existing C, C++, Python, Go, JavaScript, or TypeScript code to Rust while preserving its agreed observable behaviour. Use for requested Rust migrations or rewrites, not conceptual language comparisons or unrelated Rust edits.

7 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 6 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the source, callers, tests, build configuration, and relevant data formats before editing.

    line 12
  2. Distinctive:

    Run the original tests when practical and record the source revision and environment.

    line 14
  3. Distinctive:

    Before translating a language's representations, read only its relevant guide:

    line 24
  4. Distinctive:

    Keep ordinary ports safe. Where an ABI or demonstrated requirement needs unsafe code, isolate it behind a sound boundary and document the …

    line 30
  5. Distinctive:

    When the original is executable, compare it with the port on representative and boundary inputs, covering returned values, error …

    line 42
  6. Very specific:

    Write concise PORTING.md notes, or use the repository's established migration document, with:

    line 44
  7. Distinctive:

    Check these notes against the final code before returning.

    line 50

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust port

Port the behaviour into idiomatic Rust. Keep the work within the requested module, interfaces, and deployment constraints. This skill is independently usable; an installed Rust writing skill may supplement it but is not required.

Establish compatibility

Read the source, callers, tests, build configuration, and relevant data formats before editing. Identify the public operations, input domain, output bytes and ordering, error/absence semantics, numeric ranges, encoding, resource ownership, concurrency, and external interfaces that callers observe. Distinguish requirements from incidental implementation structure.

Run the original tests when practical and record the source revision and environment. If tests are missing, establish characterisation cases before replacing the implementation. Existing tests are evidence, not a complete definition of the supported contract.

Preserve specified behaviour and understood quirks unless the user authorises a change. Do not silently narrow accepted Unicode, whitespace, numeric ranges, missing values, or input sizes because Rust's defaults differ. Record a proposed difference and obtain agreement before relying on it; writing it in porting notes does not authorise it. If the contract is ambiguous, ask about the material ambiguity while progressing on independent parts. Do not reproduce source undefined behaviour or introduce Rust unsoundness to imitate it; identify the gap and establish defined behaviour.

Translate evidence before implementation

Port the source tests first, keeping a traceable mapping to their Rust coverage. Test grouping can change if every original assertion and behaviour remains accounted for. Add boundary cases for semantic differences the translation could introduce, including empty/invalid inputs, ordering ties, overflow, and cleanup after partial failure.

Design Rust types and signatures from that contract, then implement against the tests. Prefer ownership and RAII, Option for absence, Result for expected failure, and enums for meaningful state distinctions. Preserve error data callers use; do not collapse distinct missing states or failure categories. Public errors in a std-based library implement Display and std::error::Error; explain the compatible alternative for other targets. Use borrowed slices or strings according to the actual data, not merely the source's spelling.

Before translating a language's representations, read only its relevant guide:

  • C and C++: bytes, pointers, ABI, buffers, and lifetimes.
  • Python: Unicode, integers, ordering, and exceptions.
  • Go, JavaScript, and TypeScript: nil/missing states, numbers, iteration, and concurrency.

Keep ordinary ports safe. Where an ABI or demonstrated requirement needs unsafe code, isolate it behind a sound boundary and document the invariants. Do not retain raw pointers simply because the source used them.

Keep the design proportionate

Prefer standard Rust facilities when they satisfy the agreed contract. Use a small compatibility adapter where required, rather than recreating an entire source runtime. Avoid speculative builders, traits, public operations, and dependencies. Keep an existing algorithm unless a concrete requirement justifies a change, and verify any replacement preserves the agreed behaviour.

Investigate disproportionate growth as a design signal; do not enforce arbitrary source-to-Rust line-count ratios. Choose differential tests and fuzzing according to the input surface and risk. Do not dismiss discovered divergences as exotic without checking whether they are supported inputs.

Verify and hand over

Run the project's documented Rust formatting, lint, build, and test checks with the supported edition, MSRV, features, and targets. If none are documented, start with cargo fmt --check, cargo clippy --all-targets, and cargo test; run builds or integration checks for the affected deliverables. Fix failures introduced by the port and distinguish existing failures or unavailable checks. Do not claim a command ran or passed when it did not.

When the original is executable, compare it with the port on representative and boundary inputs, covering returned values, error categories, ordering, and relevant side effects. Passing examples do not prove equivalence over every input. Report any remaining compatibility gaps explicitly.

Write concise PORTING.md notes, or use the repository's established migration document, with:

  • API and test mappings, including how each original behaviour is covered.
  • Preserved quirks, approved differences, and unresolved compatibility gaps.
  • Verification commands and their actual results, including unavailable checks.

Check these notes against the final code before returning. Keep speculative improvements separate from the compatibility claim.

Attribution

Adapted from Morgan Linton's BeautifulRust. See NOTICE.md for provenance and LICENSE for the retained MIT notice.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.