一键导入
rust-refactor
Find duplication in Rust code and consolidate it using Traits, Generics, shared functions, and macros. Use when asked to reduce Rust code duplication.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Find duplication in Rust code and consolidate it using Traits, Generics, shared functions, and macros. Use when asked to reduce Rust code duplication.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Write the next version entry at the top of CHANGELOG.md by summarizing all changes since the last tagged release. Use when preparing release notes.
Audit GitHub Actions workflows for efficiency and recommend fixes to reduce CI minutes and costs. Use when asked to improve CI performance.
Fix CI failures in a loop until all GitHub workflow runs on the current branch are green. Use when CI is failing and needs automated repair.
AI-powered security scanner — OWASP Top 10, CWE Top 25, KMIP authorization, FIPS gating, memory safety, side-channel, supply chain, and 20 vulnerability families. Use when asked to review code security, audit KMIP access control, or scan for vulnerabilities.
Comprehensive cryptographic audit: FIPS 140-3, BSI TR-02102, ANSSI, NIST SP 800-series compliance, algorithm allow-list, key sizes, feature-flag gating, OpenSSL provider init, key lifecycle, multi-standard matrix, and academic cryptanalysis cross-check. Use when touching crate/crypto/, algorithm selection, or key management code.
Comprehensive security audit orchestrator: invokes /security-review, /cryptography-review, /threat-model, and /standards-review in sequence. Produces a unified go/no-go report. Use for full security audit before release or after significant changes.
| name | rust-refactor |
| description | Find duplication in Rust code and consolidate it using Traits, Generics, shared functions, and macros. Use when asked to reduce Rust code duplication. |
Find opportunities to reduce LOC and consolidate duplicated behavior using Traits, Generics, shared functions, and macros.
# Find clone-heavy code
rg "\.clone\(\)" --stats | tail -5
# Spot copy-paste (identical blocks ≥ 5 lines) across target crate(s)
rg -l "fn create_" crate/server/src/core/operations/
Run the Duplication Scan checklist:
match arms that repeat the same multi-line logicimpl blocks that repeat the same methods on different typesFrom / Into candidates)if cfg!(feature = "...") guards around the same patternFor each duplicate, pick the minimum sufficient Rust pattern:
| Smell | Pattern |
|---|---|
| Same logic on N types | Generic function / impl<T: Bound> |
| Same interface, different impls | Trait + impl Trait for Type |
Repetitive match / boilerplate impls | Declarative macro (macro_rules!) |
| Cross-cutting behaviour (logging, auth) | Blanket impl or extension trait |
| Repeated struct field group | Composition / newtype |
Repeated From/Into conversions | Derive macro or impl From<X> for Y |
| Repeated KMIP operation boilerplate | macro_rules! dispatch helpers |
Create a ranked list ordered by: impact (lines saved) ÷ risk (tests affected). Present it to the user before touching code:
[HIGH] Extract `KeyOperations` trait — saves ~120 LOC, touches 3 files
[MED] Generic `retrieve<T: KmipObject>` — saves ~60 LOC, touches 2 files
[LOW] `macro_rules! impl_kmip_response!` — saves ~30 LOC, touches 5 files
cargo clippy-all and cargo fmt --all.cargo test -p <crate>.cargo clippy-all # zero warnings
cargo fmt --all # no formatting drift
cargo test -p <crate> # affected crate(s) only
git diff --stat # every hunk explainable by the task
dyn Trait unless the set of types is open at runtime.#[allow(clippy::...)] only with an inline comment explaining why the lint cannot be satisfied.rg "fn_name" --type rust.use statements) always go at the top of the file — never inline inside function bodies.#[cfg(feature = "non-fips")] on the fn, not inside the body.// Before: duplicated retrieve logic in get.rs, export.rs, decrypt.rs
async fn get_object(uid: &str, db: &dyn Database) -> KResult<KmipObject> { ... }
async fn export_object(uid: &str, db: &dyn Database) -> KResult<KmipObject> { ... }
// After: shared generic with trait bound
async fn retrieve_object<P: Permission>(
uid: &str,
caller: &str,
db: &dyn Database,
) -> KResult<KmipObject>
where P: CheckAccess { ... }
macro_rules! dispatch_operation {
($op:expr, $kms:expr, $params:expr) => {
match $op {
Operation::Get(req) => get::get($kms, req, $params).await,
Operation::Locate(req) => locate::locate($kms, req, $params).await,
// ...
}
};
}
// Before: raw String everywhere — easy to mix up key UID and user ID
fn get_key(uid: String, owner: String) -> ...
// After: newtypes prevent accidental parameter swap
struct KeyUid(String);
struct UserId(String);
fn get_key(uid: KeyUid, owner: UserId) -> ...