用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-rust --skill trait-generics命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 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 |
Master Rust's powerful type system with traits and generics.
pub trait Summary {
// Required method
fn summarize(&self) -> String;
// Default implementation
fn preview(&self) -> String {
format!("Read more: {}", self.summarize())
}
}
struct Article {
title: String,
author: String,
content: String,
}
impl Summary for Article {
fn summarize(&self) -> String {
format!("{} by {}", self.title, self.author)
}
}
// 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,
{
// ...
}
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()
}
}
// 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),
];
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)
}
}
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
#[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() |