Skip to content

morganlinton/BeautifulRust / skills/rust-port

rust-port

Verified

Port code from C, C++, Python, Go, JavaScript, or TypeScript into idiomatic Rust that keeps the original behavior: ownership instead of manual memory, Result instead of error codes and exceptions, enums instead of flag ints and magic strings, and tests that prove the port matches. Use this whenever the user asks to port, translate, convert, migrate, or rewrite code in Rust ("rewrite this in Rust", "what would this look like in Rust", "move this module to Rust"), even if they don't say "port". Pairs with the rust-best-practices skill, which covers the target code's style.

FileKindSize
SKILL.mdskill md8.1 KB
evals/port-c-config-parser/case.yamlconfig663 B
evals/port-c-config-parser/files/config.cother5.1 KB
evals/port-c-config-parser/files/config.hother1.3 KB
evals/port-c-config-parser/files/test_config.cother2.9 KB
evals/port-c-config-parser/graders/01-builds-and-tests-pass.mdmarkdown114 B
evals/port-c-config-parser/graders/02-clippy-clean.mdmarkdown89 B
evals/port-c-config-parser/graders/03-no-unsafe.mdmarkdown96 B
evals/port-c-config-parser/graders/04-every-test-ported.mdmarkdown289 B
evals/port-c-config-parser/graders/05-errors-as-result.mdmarkdown209 B
evals/port-c-config-parser/graders/06-error-implements-error.mdmarkdown108 B
evals/port-c-config-parser/graders/07-option-for-absent.mdmarkdown185 B
evals/port-c-config-parser/graders/08-typed-flags.mdmarkdown144 B
evals/port-c-config-parser/graders/09-behavior-preserved.mdmarkdown320 B
evals/port-c-config-parser/graders/10-porting-notes.mdmarkdown183 B
evals/port-c-config-parser/graders/11-proportionate.mdmarkdown467 B
evals/port-c-config-parser/place-files.shexecutablescript62 B
evals/port-c-config-parser/prompt.mdmarkdown459 B
evals/port-python-task-graph/case.yamlconfig628 B
evals/port-python-task-graph/files/taskgraph.pyscript4.1 KB
evals/port-python-task-graph/files/test_taskgraph.pyscript2.7 KB
evals/port-python-task-graph/graders/01-builds-and-tests-pass.mdmarkdown114 B
evals/port-python-task-graph/graders/02-clippy-clean.mdmarkdown89 B
evals/port-python-task-graph/graders/03-every-test-ported.mdmarkdown206 B
evals/port-python-task-graph/graders/04-exceptions-as-error-enum.mdmarkdown252 B
evals/port-python-task-graph/graders/05-kind-is-enum.mdmarkdown134 B
evals/port-python-task-graph/graders/06-priority-is-option.mdmarkdown105 B
evals/port-python-task-graph/graders/07-definition-order-preserved.mdmarkdown204 B
evals/port-python-task-graph/graders/08-order-and-cycle-match.mdmarkdown187 B
evals/port-python-task-graph/graders/09-summary-every-kind-in-order.mdmarkdown146 B
evals/port-python-task-graph/graders/10-porting-notes.mdmarkdown198 B
evals/port-python-task-graph/graders/11-proportionate.mdmarkdown473 B
evals/port-python-task-graph/place-files.shexecutablescript62 B
evals/port-python-task-graph/prompt.mdmarkdown435 B

evals/port-python-task-graph/files/taskgraph.py

View on GitHub
"""Parse a small task-definition format and compute a deterministic run order.

Format, one task per line:

    name: kind [p=N] <- dep1, dep2

`kind` is one of build, test, deploy. `[p=N]` is an optional integer priority
(higher runs first among tasks that are ready at the same time). `<- deps` is
optional. Blank lines and lines starting with '#' are ignored.
"""

KINDS = ("build", "test", "deploy")


class TaskError(Exception):
    """Base class for every error this module raises."""


class ParseError(TaskError):
    def __init__(self, line_no, message):
        super().__init__(f"line {line_no}: {message}")
        self.line_no = line_no


class MissingDependency(TaskError):
    def __init__(self, task, dep):
        super().__init__(f"{task} depends on unknown task {dep}")
        self.task = task
        self.dep = dep


class CycleError(TaskError):
    def __init__(self, cycle):
        super().__init__("cycle: " + " -> ".join(cycle))
        self.cycle = cycle


class Task:
    def __init__(self, name, kind, deps=None, priority=None):
        self.name = name
        self.kind = kind
        self.deps = deps or []
        self.priority = priority

    def __repr__(self):
        return f"Task({self.name!r}, {self.kind!r}, {self.deps!r}, {self.priority!r})"


def parse_tasks(text):
    """Returns a dict of name -> Task, in the order tasks were defined."""
    tasks = {}
    for line_no, raw in enumerate(text.splitlines(), start=1):
        line = raw.strip()
        if not line or line.startswith("#"):
            continue
        if ":" not in line:
            raise ParseError(line_no, "expected 'name: kind'")
        name, rest = line.split(":", 1)
        name = name.strip()
        if not name or not name.replace("-", "").replace("_", "").isalnum():
            raise ParseError(line_no, f"bad task name {name!r}")
        if name in tasks:
            raise ParseError(line_no, f"duplicate task {name}")
        deps = []
        if "<-" in rest:
            rest, dep_text = rest.split("<-", 1)
            deps = [d.strip() for d in dep_text.split(",") if d.strip()]
        priority = None
        if "[p=" in rest:
            rest, prio_text = rest.split("[p=", 1)
            if not prio_text.strip().endswith("]"):
                raise ParseError(line_no, "unclosed priority")
            try:
                priority = int(prio_text.strip()[:-1])
            except ValueError:
                raise ParseError(line_no, "priority must be an integer")
        kind = rest.strip()
        if kind not in KINDS:
            raise ParseError(line_no, f"unknown kind {kind!r}")
        tasks[name] = Task(name, kind, deps, priority)
    return tasks


def _ready_key(task):
    # Higher priority first; tasks without a priority come after all that have one;
    # ties broken by name.
    has = task.priority is not None
    return (not has, -(task.priority or 0), task.name)


def execution_order(tasks):
    """Returns task names in a valid run order.

    Raises MissingDependency for a dependency that isn't defined and CycleError,
    naming the cycle, if no order exists.
    """
    for t in tasks.values():
        for d in t.deps:
            if d not in tasks:
                raise MissingDependency(t.name, d)
    remaining = {name: set(t.deps) for name, t in tasks.items()}
    order = []
    while remaining:
        ready = [tasks[n] for n, deps in remaining.items() if not deps]
        if not ready:
            raise CycleError(_find_cycle(tasks, remaining))
        nxt = min(ready, key=_ready_key)
        order.append(nxt.name)
        del remaining[nxt.name]
        for deps in remaining.values():
            deps.discard(nxt.name)
    return order


def _find_cycle(tasks, remaining):
    start = min(remaining)
    path, seen = [], {}
    node = start
    while node not in seen:
        seen[node] = len(path)
        path.append(node)
        node = min(d for d in tasks[node].deps if d in remaining)
    return path[seen[node]:] + [node]


def summarize(tasks):
    """Returns a count of tasks per kind, for every kind, in KINDS order."""
    counts = {k: 0 for k in KINDS}
    for t in tasks.values():
        counts[t.kind] += 1
    return counts
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall