- name
SKILL.md
Tệp skill vẫn nằm trong kho mã của nhà phát hành.
Dán lệnh đã sao chép vào terminal. Lệnh sẽ cài đặt tệp SKILL.md này vào agent đó.
npx skills add morganlinton/BeautifulRust --skill rust-port -a cursor -yDán lệnh đã sao chép vào terminal. Lệnh sẽ cài đặt tệp SKILL.md này vào agent đó.
npx skills add morganlinton/BeautifulRust --skill rust-port -a claude-code -yDán lệnh đã sao chép vào terminal. Lệnh sẽ cài đặt tệp SKILL.md này vào agent đó.
npx skills add morganlinton/BeautifulRust --skill rust-port -a codex -yDán lệnh đã sao chép vào terminal. Lệnh sẽ cài đặt tệp SKILL.md này vào agent đó.
npx skills add morganlinton/BeautifulRust --skill rust-port -a grok -yGửi tin nhắn đã sao chép trong cuộc trò chuyện Grok Bot. Bot sẽ lấy tệp SKILL.md này từ GitHub và thêm vào bộ skill mà mọi Bot của bạn dùng chung.
Install this skill: https://github.com/morganlinton/BeautifulRust/tree/HEAD/skills/rust-portTừ nhà phát hành
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.mdCâu hỏi thường gặp
Tải skills/rust-port/SKILL.md từ nhà phát hành, hoặc sao chép đường dẫn và mở kho mã. PlugMCP chỉ liệt kê skill và không lưu trữ tệp này.
Nhà phát hành duy trì nó tại https://github.com/morganlinton/BeautifulRust.
Claude, Cursor, Codex và Grok Build có thể đọc tệp SKILL.md mà bạn thêm từ kho mã của nhà phát hành. Grok Bot cài đặt skill khi bạn gửi liên kết thư mục GitHub của skill trong cuộc trò chuyện.