rust-type-system
Skill4 starsChanged 3 months agoApache-2.0View on GitHub
Deep understanding of Rust's type system including generics, traits, trait objects, associated types, GATs, and type-level programming. Use when designing generic APIs, choosing between static and dynamic dispatch, implementing complex trait bounds, or encoding invariants in types.
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 124
Rule: Use associated types when there's one natural implementation.
- Very specific: line 129
All methods have &self or &mut self receiver (not self or no self)
- Very specific: line 130
No methods return Self
- Distinctive: line 131
No methods have generic type parameters
- Distinctive: line 132
No associated functions (methods without self)
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust Type System
Based on Effective Rust, The Rust Reference, and The Rust Programming Language.
When to Use This Skill
- Choosing between generics (monomorphization) and trait objects (dynamic dispatch)
- Writing complex where clauses and trait bounds
- Using associated types vs type parameters
- Understanding object safety rules
- Implementing GATs (Generic Associated Types)
- Using PhantomData for type-level programming
- Encoding invariants with the type system
Generics vs Trait Objects
Generics (Static Dispatch)
fn largest<T: PartialOrd>(list: &[T]) -> &T {
let mut largest = &list[0];
for item in &list[1..] {
if item > largest { largest = item; }
}
largest
}- Monomorphized: separate code generated for each concrete type
- Zero runtime cost (no vtable indirection)
- Larger binary (code duplication)
- Type known at compile time
Trait Objects (Dynamic Dispatch)
fn draw_all(shapes: &[&dyn Draw]) {
for shape in shapes {
shape.draw(); // vtable lookup at runtime
}
}- Single code path for all types
- Slight runtime cost (vtable pointer + indirect call)
- Smaller binary
- Type erased — heterogeneous collections possible
Decision Matrix
| Factor | Generics | Trait Objects |
| Performance | Faster (inlined) | Indirect call overhead |
| Binary size | Larger | Smaller |
| Heterogeneous collections | No | Yes |
| Compile time | Longer | Shorter |
| Downcasting possible | No (type erased) | Via Any |
Trait Bounds
Syntax Variants
// Where clause (preferred for complex bounds)
fn process<T, U>(x: T, y: U) -> String
where
T: Display + Clone + Send,
U: Into<String> + Debug,
{ ... }
// Inline bounds (for simple cases)
fn print<T: Display>(val: T) { println!("{val}"); }
// impl Trait (argument position — sugar for generics)
fn process(val: impl Display + Clone) { ... }
// impl Trait (return position — opaque type)
fn make_iter() -> impl Iterator<Item = u32> { (0..10).filter(|x| x % 2 == 0) }Useful Bound Combinations
T: Send + Sync + 'static // thread-safe, no borrows
T: Default + Clone // can create and duplicate
T: Serialize + DeserializeOwned // full serde support
T: AsRef<Path> // accepts &str, String, PathBuf, &Path
T: Into<String> // accepts String, &str (via allocation)Associated Types vs Type Parameters
Associated Types (one implementation per type)
trait Iterator {
type Item; // determined by the implementor
fn next(&mut self) -> Option<Self::Item>;
}
impl Iterator for Counter {
type Item = u32; // Counter always yields u32
fn next(&mut self) -> Option<u32> { ... }
}Type Parameters (multiple implementations per type)
trait From<T> {
fn from(val: T) -> Self;
}
// String can implement From<&str>, From<Vec<u8>>, etc.
impl From<&str> for String { ... }
impl From<Vec<u8>> for String { ... }Rule: Use associated types when there's one natural implementation. Use type parameters when a type could have multiple.
Object Safety
A trait is object-safe (can be used as dyn Trait) if:
- All methods have
&selfor&mut selfreceiver (notselfor no self) - No methods return
Self - No methods have generic type parameters
- No associated functions (methods without self)
- No
where Self: Sizedbounds on the trait itself
// Object-safe
trait Draw {
fn draw(&self);
fn bounds(&self) -> Rect;
}
// NOT object-safe (returns Self)
trait Clone {
fn clone(&self) -> Self;
}
// Workaround: separate object-safe subset
trait CloneBox {
fn clone_box(&self) -> Box<dyn CloneBox>;
}Generic Associated Types (GATs)
trait LendingIterator {
type Item<'a> where Self: 'a;
fn next(&mut self) -> Option<Self::Item<'_>>;
}
// Can return references to internal state
impl LendingIterator for WindowsMut {
type Item<'a> = &'a mut [u8] where Self: 'a;
fn next(&mut self) -> Option<&mut [u8]> { ... }
}PhantomData
Mark type parameters that don't appear in fields:
use std::marker::PhantomData;
struct Slice<'a, T> {
ptr: *const T,
len: usize,
_lifetime: PhantomData<&'a T>, // owns a &'a T conceptually
}
// Typestate marker
struct Authenticated;
struct Anonymous;
struct Client<State> {
token: Option<String>,
_state: PhantomData<State>,
}Sealed Traits
Prevent external implementations:
mod private {
pub trait Sealed {}
}
pub trait MyTrait: private::Sealed {
fn method(&self);
}
// Only types in this crate can implement MyTrait
pub struct MyType;
impl private::Sealed for MyType {}
impl MyTrait for MyType { fn method(&self) { } }Reference Map
references/generics-monomorphization.md— generic functions, methods, impl blocksreferences/traits-bounds.md— trait bounds, supertraits, blanket impls, coherencereferences/advanced-types.md— GATs, existential types, type-level programming
Key References
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- adxptived/Rust-Skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository80 other files it gives its agents.
- a11y-accessibility-designSkill
- agentic-ui-patternsSkill
- ai-native-ui-designSkill
- ai-ui-anti-patternsSkill
- ai-ui-heuristicsSkill
- calm-technology-uiSkill
- conversion-growth-designSkill
- cross-platform-designSkill
- dark-mode-designSkill
- data-visualizationSkill
- design-systemsSkill
- design-thinking-processSkill
- error-empty-statesSkill
- ethical-design-patternsSkill
- form-uxSkill
- information-architectureSkill
- interaction-design-patternsSkill
- internationalization-uiSkill
- mobile-touch-designSkill
- modal-classes-lifecycleSkill
- modal-container-imagesSkill
- modal-dicts-queuesSkill
- modal-endpointsSkill
- modal-fundamentalsSkill
- modal-gpu-computeSkill
- modal-networkingSkill
- modal-observabilitySkill
- modal-parallel-executionSkill
- modal-sandboxesSkill
- modal-scaling-performanceSkill
- modal-schedulingSkill
- modal-secretsSkill
- modal-serversSkill
- modal-storageSkill
- modal-web-servingSkill
- modal-workspace-adminSkill
- motion-design-principlesSkill
- notifications-permissionsSkill
- onboarding-uxSkill
- rust-api-designSkill
- rust-async-programmingSkill
- rust-cargo-masterySkill
- rust-cli-applicationsSkill
- rust-clippy-lintsSkill
- rust-closures-iteratorsSkill
- rust-compiler-internalsSkill
- rust-concurrencySkill
- rust-design-patternsSkill
- rust-editionsSkill
- rust-embeddedSkill
- rust-error-handlingSkill
- rust-game-developmentSkill
- rust-lifetimes-borrowingSkill
- rust-macrosSkill
- rust-performanceSkill
- rust-rustdocSkill
- rust-rustup-toolchainSkill
- rust-smart-pointersSkill
- rust-testing-benchmarkingSkill
- rust-unsafe-ffiSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

