Rust

From edochi/mdvs · View interactive version

Rust is an AI agent skill from the GitHub repository edochi/mdvs. Rust coding conventions. Apply when writing, reviewing, or modifying Rust code. Covers error handling, types, ownership, testing, and anti-patterns.

How to use this skill

Skill file

Rust Coding Conventions

Error Handling

variant name describes the failure, #[error("...")] format string includes

diagnostic context (sizes, IDs), use #[from] for transparent wrapping of

upstream errors

library crates

Borrowing & Ownership

reconsider the data flow

Type Design

pub struct Port(pub u16)

Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize — include

only what's semantically correct

types

output

Documentation Style

what and how

design rationale)

encoding details)

point

Testing Conventions

buffer_duplicate_insert_ignored)

assert equality

testing one logical behavior

"is error"

Iterators & Collections

Clippy & Linting

the lint no longer triggers

needless_collect

Anti-Patterns

| Anti-Pattern | Why Bad | Better |

| ------------------------------- | ------------------------ | ------------------------------------------ |

| .clone() everywhere | Hides ownership issues | Proper references or restructure data flow |

| .unwrap() in library code | Runtime panics | ?, or handle the error |

| String in function params | Unnecessary allocation | &str, Cow<str> |

| Index-based loops | Error-prone, unidiomatic | Iterators |

| Rc/Arc when single owner | Unnecessary overhead | Simple ownership |

| Giant match arms | Unmaintainable | Extract to methods |

| Ignoring #[must_use] | Silently dropped errors | Handle or let _ = |

| unsafe without SAFETY comment | UB risk, no audit trail | Document invariants or find safe pattern |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.