← Back to list

trait-generics
by pluginagentmarketplace
Rust programming language roadmap plugin for Claude
⭐ 1🍴 0📅 Jan 5, 2026
SKILL.md
name: trait-generics description: Master Rust traits, generics, and type system sasmp_version: "1.3.0" bonded_agent: rust-type-system-agent bond_type: PRIMARY_BOND version: "1.0.0"
Traits & Generics Skill
Master Rust's powerful type system with traits and generics.
Quick Start
Defining Traits
pub trait Summary {
// Required method
fn summarize(&self) -> String;
// Default implementation
fn preview(&self) -> String {
format!("Read more: {}", self.summarize())
}
}
Implementing Traits
struct Article {
title: String,
author: String,
content: String,
}
impl Summary for Article {
fn summarize(&self) -> String {
format!("{} by {}", self.title, self.author)
}
}
Generic Functions
// impl Trait syntax
fn print_summary(item: &impl Summary) {
println!("{}", item.summarize());
}
// Trait bound syntax
fn print_summary<T: Summary>(item: &T) {
println!("{}", item.summarize());
}
// Multiple bounds
fn process<T: Summary + Clone>(item: &T) {
let copy = item.clone();
println!("{}", copy.summarize());
}
// Where clause
fn complex<T, U>(t: T, u: U)
where
T: Summary + Clone,
U: std::fmt::Debug,
{
// ...
}
Generic Structs
struct Point<T> {
x: T,
y: T,
}
impl<T> Point<T> {
fn new(x: T, y: T) -> Self {
Point { x, y }
}
}
// Specific implementations
impl Point<f64> {
fn distance(&self) -> f64 {
(self.x.powi(2) + self.y.powi(2)).sqrt()
}
}
Common Patterns
Static vs Dynamic Dispatch
// Static dispatch (monomorphization, zero-cost)
fn process_static(item: &impl Summary) {
println!("{}", item.summarize());
}
// Dynamic dispatch (trait object, runtime cost)
fn process_dynamic(item: &dyn Summary) {
println!("{}", item.summarize());
}
// Collection of different types
let items: Vec<Box<dyn Summary>> = vec![
Box::new(article),
Box::new(tweet),
];
Associated Types
trait Container {
type Item;
fn get(&self, index: usize) -> Option<&Self::Item>;
}
impl<T> Container for Vec<T> {
type Item = T;
fn get(&self, index: usize) -> Option<&Self::Item> {
<[T]>::get(self, index)
}
}
Operator Overloading
use std::ops::Add;
#[derive(Debug, Copy, Clone)]
struct Point {
x: i32,
y: i32,
}
impl Add for Point {
type Output = Point;
fn add(self, other: Point) -> Point {
Point {
x: self.x + other.x,
y: self.y + other.y,
}
}
}
let p3 = p1 + p2; // Uses Add trait
Derivable Traits
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
struct Config {
timeout: u64,
retries: u32,
}
| Trait | Purpose |
|---|---|
| Debug | {:?} formatting |
| Clone | Explicit deep copy |
| Copy | Implicit bitwise copy |
| PartialEq | == comparison |
| Eq | Total equality |
| Hash | Use in HashMap |
| Default | Default::default() |
Resources
Score
Total Score
60/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
Reviews
💬
Reviews coming soon