Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Design and review Rust trait APIs, generic bounds, dispatch models, and conversion contracts for clear public interfaces. Use when designing, refactoring, or reviewing traits, generics, trait objects, associated types, impl Trait, From/TryFrom, AsRef, Borrow, or crate APIs.
.claude/skills/hashgraph-online-rust-trait-api-design/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-15 | ✗→✓ | ▲ Improved | 9% | 0% |
| case-13 | ✓→✓ | = Same ✓ | 22% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 50% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 3% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 9% | 0% |
Use this skill to make Rust APIs generic where useful, concrete where simpler, and object-safe when dynamic dispatch is part of the design. Optimize for the smallest capability contract that callers and implementors can understand.
behavior.
callers or implementations need the flexibility.
Trait for heterogeneous values, plugin-like extension points, or runtime dispatch.
where clauses whenbounds are long or involve associated types.
keep fields private, or use constructors when invariants must not be implemented externally.
custom conversion trait before checking From, TryFrom, AsRef, AsMut, Borrow, ToOwned, and Cow.
callable the way the skill expects future users to call it.
impl Trait or a named generic for parameters when callers shouldpass many concrete types.
impl Trait when hiding one concrete return type. Return Box<dynTrait> when the concrete type varies at runtime.
type. Prefer generic trait parameters when one implementation supports many target types.
From for infallible conversions and TryFrom for fallibleconversions. Implementing these gives callers Into and TryInto.
AsRef for cheap reference-to-reference conversion. Use Borrow onlywhen borrowed and owned forms have equivalent Eq, Hash, and Ord behavior.
Copy bounds unless the algorithm semantically requires bitwise copy.Read references/trait-api-patterns.md when choosing between generics and dyn Trait, or when public traits fail object-safety checks.
Before making a public trait object-safe, check:
Self unless constrained with where Self: Sized.&dyn Trait, Box<dyn Trait>, orArc<dyn Trait + Send + Sync>.
&Vec<T> because it only needs iteration.String and immediately borrows it as &str.Into directly instead of From.dispatch is required.
async-trait is used in a public trait without checking whether nativeasync fn in traits, trait-variant, or boxed futures fit the dispatch and Send needs better.
Other measured skills in the registry, with their headline benchmark lift.