一键导入
conversion-method-naming
Use when naming a conversion or accessor method in Rust — follow the Rust API naming conventions for the method's cost and ownership.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when naming a conversion or accessor method in Rust — follow the Rust API naming conventions for the method's cost and ownership.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Enforce type-signature conventions for public Miden Assembly (.masm) procedures. Use when adding, editing, or reviewing a `pub proc` signature — parameter and return types, semantic type aliases, struct/array/tuple types, and how the signature maps onto the operand stack and the doc-comment Inputs/Outputs.
Enforce inline commenting conventions for Miden Assembly (.masm) files. Use when editing, reviewing, or creating .masm files.
Enforce doc comment conventions for Miden Assembly (.masm) procedures. Use when editing, reviewing, or creating .masm procedures, especially when documenting inputs, outputs, panic conditions, or invocation types.
Use when writing kernel, account, or note MASM code that reads from or writes to the advice provider (advice stack / advice map) — validate advice data.
Use when writing a Rust test that exercises a failure path or a MASM test that expects a `panic` / `assert` — assert on the specific expected error variant or error code.
Use when writing or reviewing MASM hot paths — prefer the cheaper equivalent instruction: `neq.0` over `gt.0` for non-zero checks, `cdrop` over an `if/else` selecting between two values, `dup.N` over `loc_load` for a value still on the stack, `eqw` over element-wise word comparison, `u32gt`/`u32lt` over generic `gt`/`lt` on known-u32 operands.
| name | conversion-method-naming |
| description | Use when naming a conversion or accessor method in Rust — follow the Rust API naming conventions for the method's cost and ownership. |
Pick the prefix that matches the cost and ownership of the conversion:
as_<type> — free or near-free, returns a borrow (e.g. as_bytes() -> &[u8]).to_<type> — non-trivial cost, returns an owned value, leaves self intact (e.g. to_string() -> String).into_<type> — consumes self, returns the inner/converted value.from_<type> — associated function on the target type that constructs it.with_<field> — only for builder-style methods that take and return Self with a field set.Do not name a non-borrowing method as_*. Do not name a non-builder method with_*. Do not use to_* for a free borrow.
The prefixes come from the Rust API guidelines and are baked into the standard library: readers expect as_ to be cheap, to_ to allocate, into_ to consume, and with_ to return Self. Violating that costs every reader a moment of confusion and erodes trust in the API.
// Good
impl Header {
pub fn as_bytes(&self) -> &[u8] { ... } // cheap borrow
pub fn to_vec(&self) -> Vec<u8> { ... } // allocates
pub fn into_payload(self) -> Payload { self.payload } // consumes
}
impl HeaderBuilder {
pub fn with_version(mut self, v: u8) -> Self { self.version = v; self }
}
// Bad
impl Header {
pub fn as_vec(&self) -> Vec<u8> { ... } // allocates, should be to_vec
pub fn to_bytes(&self) -> &[u8] { ... } // borrow, should be as_bytes
}
// Bad: with_* on a non-builder method
fn with_seed(rng: &mut Rng, seed: u64) { ... } // not returning Self