Rust Trait Explorer

actionbook/rust-skills/skills/rust-trait-explorer

作者 actionbook5c40d3ad7851无许可证1.5K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库6周前更新

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

AI 生成的概览

使用 LSP 导航和 grep 探索 Rust trait 实现及类型与 trait 的关系。

功能
该技能引导智能体先定位 Rust trait 或结构体定义,再通过 goToImplementation、documentSymbol 等 LSP 操作以及 grep 搜索 impl 块,找出其实现或所实现的 trait。它会生成结构化报告:含位置的实现者表格、实现细节、按来源分组的 trait 列表、层级图、覆盖检查以及 blanket 实现说明。
适用场景
当需要查询谁实现了某个 Rust trait、某个类型实现了哪些 trait,或了解 trait 层级结构时使用。也适用于覆盖检查和理解 Rust 代码库中的多态设计。
运行要求
需要 Rust 的 LSP 工具,以及对项目源码的 Read、Glob 和 Grep 访问权限。不附带脚本,仅为指令。

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
​```rustpub 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​```rustimpl Handler for AuthHandler {    fn handle(&self, request: Request) -> Response {        // Authentication logic    }
    fn name(&self) -> &str {        "auth"    }}​```
#### ApiHandler​```rustimpl 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 SaysAction
"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

WhenSee
Navigate to implrust-code-navigator
Call relationshipsrust-call-graph
Project structurerust-symbol-analyzer
Safe refactoringrust-refactor-helper

来源与署名

来源:actionbook/rust-skills位于skills/rust-trait-explorer提交5c40d3a

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架

Rust Trait Explorer · skills/rust-trait-explorer 智能体技能 | SourceWeft