- name
SKILL.md
技能文件保留在发布者的仓库中。
在终端中粘贴复制的命令。它会把这个 SKILL.md 安装到对应的智能体中。
npx skills add morganlinton/BeautifulRust --skill rust-port -a cursor -y在终端中粘贴复制的命令。它会把这个 SKILL.md 安装到对应的智能体中。
npx skills add morganlinton/BeautifulRust --skill rust-port -a claude-code -y在终端中粘贴复制的命令。它会把这个 SKILL.md 安装到对应的智能体中。
npx skills add morganlinton/BeautifulRust --skill rust-port -a codex -y在终端中粘贴复制的命令。它会把这个 SKILL.md 安装到对应的智能体中。
npx skills add morganlinton/BeautifulRust --skill rust-port -a grok -y在 Grok Bot 聊天中发送复制的消息。Bot 会从 GitHub 获取这个 SKILL.md,并添加到你所有 Bot 共享的技能中。
Install this skill: https://github.com/morganlinton/BeautifulRust/tree/HEAD/skills/rust-port来自发布者
The goal is the Rust a Rust developer would have written to solve the same problem, with
the same observable behavior. A line-by-line transliteration (C written in Rust syntax,
or Python with Box<dyn Any>) compiles but keeps every problem the original had and adds
the borrow checker on top. Port the behavior, not the structure.
NULL returns, global state,
fixed-size buffers, a class that exists only to group functions, or isinstance
checks. These don't carry over.Translate the original tests into Rust tests before porting the implementation. Keep one Rust test per original test, with a name that maps back to it, so a reader can check coverage. The tests are the definition of "same behavior". If the original has no tests, write characterization tests from the behavior list in step 1.
Decide the public types and signatures from the behavior list, not from the original's shape. Then implement against the ported tests.
Don't write unsafe or use raw pointers unless the port must talk to C through FFI, and
then confine it as the rust-best-practices skill describes.
(value, error) returns become Result; nil becomes Option; interfaces become
traits; goroutines and channels become threads with std::sync::mpsc or async tasks,
depending on what the original needs.null and undefined become Option; thrown errors become Result; plain
objects become structs; numbers become a sized integer or f64, chosen on purpose.A port that matches the original on every possible input is usually the wrong goal. Match it on the inputs it actually receives, and use Rust's standard library for the rest.
str::lines, str::trim,
str::parse, and char methods, not hand-written copies of Python's splitlines,
strip, int(), or repr(), or of C's locale-dependent isspace and strtol. Where
Rust's behavior differs only on exotic input, such as Unicode digits, non-ASCII
whitespace, or unbounded integers, list the difference in the porting notes instead of
coding around it. Write a compatibility shim only when the user says those inputs occur.Debug, Clone, Display, Error, FromStr,
Default, and IntoIterator for collections). Skip builders, Index impls,
FromIterator, Extend, and custom iterator types unless the original's callers need
them.Differential testing against the original is worth doing, but a few dozen realistic and edge-case inputs answer the question. A fuzzing harness over millions of inputs usually just finds exotic divergences that belong in the notes.
Run these if a Rust toolchain is available, and fix everything before reporting:
cargo build
cargo test
cargo clippy --all-targets -- -D warnings
Every ported test must pass. If the original's tests can be run too, run them and compare results on the same inputs.
Alongside the code, write a short PORTING.md that a reviewer can check in a few
minutes:
For the style of the Rust itself, follow the rust-best-practices skill if it is
installed.
>-
---name: rust-portdescription: >----# skills/rust-port/SKILL.md常见问题
从发布者处下载 skills/rust-port/SKILL.md,或复制路径后打开仓库。PlugMCP 只收录该技能,不托管文件。
发布者将它存放在 https://github.com/morganlinton/BeautifulRust。
Claude、Cursor、Codex 和 Grok Build 可以读取你从发布者仓库添加的 SKILL.md。在聊天中发送技能的 GitHub 文件夹链接,Grok Bot 就会安装它。