Agent skill

rust-trait-explorer

Explore Rust trait implementations using LSP. Triggers on: /trait-impl, find implementations, who implements, trait 实现, 谁实现了, 实现了哪些trait

Stars 941
Forks 87

Install this agent skill to your Project

npx add-skill https://github.com/actionbook/rust-skills/tree/main/skills/rust-trait-explorer

SKILL.md

Rust Trait Explorer

Discover trait implementations and understand polymorphic designs.

Usage

/rust-trait-explorer <TraitName|StructName>

Examples:

  • /rust-trait-explorer Handler - Find all implementors of Handler trait
  • /rust-trait-explorer MyStruct - Find all traits implemented by MyStruct

LSP Operations

Go to Implementation

Find all implementations of a trait.

LSP(
  operation: "goToImplementation",
  filePath: "src/traits.rs",
  line: 10,
  character: 11
)

Use when:

  • Trait name is known
  • Want to find all implementors
  • Understanding polymorphic code

Workflow

Find Trait Implementors

User: "Who implements the Handler trait?"
    │
    ▼
[1] Find trait definition
    LSP(goToDefinition) or workspaceSymbol
    │
    ▼
[2] Get implementations
    LSP(goToImplementation)
    │
    ▼
[3] For each impl, get details
    LSP(documentSymbol) for methods
    │
    ▼
[4] Generate implementation map

Find Traits for a Type

User: "What traits does MyStruct implement?"
    │
    ▼
[1] Find struct definition
    │
    ▼
[2] Search for "impl * for MyStruct"
    Grep pattern matching
    │
    ▼
[3] Get trait details for each
    │
    ▼
[4] Generate trait list

Output Format

Trait Implementors

## Implementations of `Handler`

**Trait defined at:** src/traits.rs:15

​```rust
pub trait Handler {
    fn handle(&self, request: Request) -> Response;
    fn name(&self) -> &str;
}
​```

### Implementors (4)

| Type | Location | Notes |
|------|----------|-------|
| AuthHandler | src/handlers/auth.rs:20 | Handles authentication |
| ApiHandler | src/handlers/api.rs:15 | REST API endpoints |
| WebSocketHandler | src/handlers/ws.rs:10 | WebSocket connections |
| MockHandler | tests/mocks.rs:5 | Test mock |

### Implementation Details

#### AuthHandler
​```rust
impl Handler for AuthHandler {
    fn handle(&self, request: Request) -> Response {
        // Authentication logic
    }

    fn name(&self) -> &str {
        "auth"
    }
}
​```

#### ApiHandler
​```rust
impl Handler for ApiHandler {
    fn handle(&self, request: Request) -> Response {
        // API routing logic
    }

    fn name(&self) -> &str {
        "api"
    }
}
​```

Traits for a Type

## Traits implemented by `User`

**Struct defined at:** src/models/user.rs:10

### Standard Library Traits
| Trait | Derived/Manual | Notes |
|-------|----------------|-------|
| Debug | #[derive] | Auto-generated |
| Clone | #[derive] | Auto-generated |
| Default | manual | Custom defaults |
| Display | manual | User-friendly output |

### Serde Traits
| Trait | Location |
|-------|----------|
| Serialize | #[derive] |
| Deserialize | #[derive] |

### Project Traits
| Trait | Location | Methods |
|-------|----------|---------|
| Entity | src/db/entity.rs:30 | id(), created_at() |
| Validatable | src/validation.rs:15 | validate() |

### Implementation Hierarchy

​```
User
├── derive
│   ├── Debug
│   ├── Clone
│   ├── Serialize
│   └── Deserialize
└── impl
    ├── Default (src/models/user.rs:50)
    ├── Display (src/models/user.rs:60)
    ├── Entity (src/models/user.rs:70)
    └── Validatable (src/models/user.rs:85)
​```

Trait Hierarchy Visualization

## Trait Hierarchy

                    ┌─────────────┐
                    │    Error    │ (std)
                    └──────┬──────┘
                           │
              ┌────────────┼────────────┐
              │            │            │
      ┌───────▼───────┐ ┌──▼──┐ ┌───────▼───────┐
      │  AppError     │ │ ... │ │  DbError      │
      └───────┬───────┘ └─────┘ └───────┬───────┘
              │                         │
      ┌───────▼───────┐         ┌───────▼───────┐
      │ AuthError     │         │ QueryError    │
      └───────────────┘         └───────────────┘

Analysis Features

Coverage Check

## Trait Implementation Coverage

Trait: Handler (3 required methods)

| Implementor | handle() | name() | priority() | Complete |
|-------------|----------|--------|------------|----------|
| AuthHandler | ✅ | ✅ | ✅ | Yes |
| ApiHandler | ✅ | ✅ | ❌ default | Yes |
| MockHandler | ✅ | ✅ | ✅ | Yes |

Blanket Implementations

## Blanket Implementations

The following blanket impls may apply to your types:

| Trait | Blanket Impl | Applies To |
|-------|--------------|------------|
| From<T> | `impl<T> From<T> for T` | All types |
| Into<U> | `impl<T, U> Into<U> for T where U: From<T>` | Types with From |
| ToString | `impl<T: Display> ToString for T` | Types with Display |

Common Patterns

User Says Action
"Who implements X?" goToImplementation on trait
"What traits does Y impl?" Grep for impl * for Y
"Show trait hierarchy" Find super-traits recursively
"Is X: Send + Sync?" Check std trait impls

Related Skills

When See
Navigate to impl rust-code-navigator
Call relationships rust-call-graph
Project structure rust-symbol-analyzer
Safe refactoring rust-refactor-helper

Expand your agent's capabilities with these related and highly-rated skills.

actionbook/rust-skills

meta-cognition-parallel

EXPERIMENTAL: Three-layer parallel meta-cognition analysis. Triggers on: /meta-parallel, 三层分析, parallel analysis, 并行元认知

941 87
Explore
actionbook/rust-skills

domain-cloud-native

Use when building cloud-native apps. Keywords: kubernetes, k8s, docker, container, grpc, tonic, microservice, service mesh, observability, tracing, metrics, health check, cloud, deployment, 云原生, 微服务, 容器

941 87
Explore
actionbook/rust-skills

m07-concurrency

CRITICAL: Use for concurrency/async. Triggers: E0277 Send Sync, cannot be sent between threads, thread, spawn, channel, mpsc, Mutex, RwLock, Atomic, async, await, Future, tokio, deadlock, race condition, 并发, 线程, 异步, 死锁

941 87
Explore
actionbook/rust-skills

unsafe-checker

CRITICAL: Use for unsafe Rust code review and FFI. Triggers on: unsafe, raw pointer, FFI, extern, transmute, *mut, *const, union, #[repr(C)], libc, std::ffi, MaybeUninit, NonNull, SAFETY comment, soundness, undefined behavior, UB, safe wrapper, memory layout, bindgen, cbindgen, CString, CStr, 安全抽象, 裸指针, 外部函数接口, 内存布局, 不安全代码, FFI 绑定, 未定义行为

941 87
Explore
actionbook/rust-skills

rust-refactor-helper

Safe Rust refactoring with LSP analysis. Triggers on: /refactor, rename symbol, move function, extract, 重构, 重命名, 提取函数, 安全重构

941 87
Explore
actionbook/rust-skills

rust-skill-creator

Use when creating skills for Rust crates or std library documentation. Keywords: create rust skill, create crate skill, create std skill, 创建 rust skill, 创建 crate skill, 创建 std skill, 动态 rust skill, 动态 crate skill, skill for tokio, skill for serde, skill for axum, generate rust skill, rust 技能, crate 技能, 从文档创建skill, from docs create skill

941 87
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results