Rust Lifetime Complex
Advanced lifetime expert covering HRTB, GAT, 'static bounds, trait object constraints, type system conflicts, and lifetime elision edge cases.triggers: - lifetime - HRTB - GAT - higher-ranked - 'static - trait object - one type is more general - lifetime conflict--- # Advanced Lifetime and Type System Expert ## Core Question Why won't this type conversion compile? The type system's boundaries are often surprising.
Install
npx skills add huiali/rust-skills --skill rust-lifetime-complexgit clone --depth 1 https://github.com/huiali/rust-skills.git /tmp/rust-skills
mkdir -p ~/.claude/skills
cp -r /tmp/rust-skills/.codex/skills/rust-lifetime-complex ~/.claude/skills/rust-lifetime-complexPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
## Solution Patterns
### Pattern 1: HRTB (Higher-Ranked Trait Bounds)
```rust
// Problem: Concrete lifetime vs generic lifetime
// ❌ This doesn't work with dyn
type ClosureFn<T> = dyn for<'a> FnOnce(&'a mut Connection) -> BoxFuture<'a, T>;
// ✅ Solution: Keep HRTB in generic bounds
async fn with_connection<F, T, Fut>(f: F) -> Result<T, Error>
where
F: for<'c> FnOnce(&'c mut Connection) -> Fut,
Fut: Future<Output = Result<T, Error>>,
{
let mut conn = get_connection().await?;
f(&mut conn).await
}
// Usage
with_connection(|conn| async move {
query("SELECT * FROM users").fetch_all(conn).await
}).await?;
```
### Pattern 2: GAT + Object Safety
```rust
// Problem: GAT makes trait non-object-safe
// ❌ Can't use dyn with GAT
trait Repository {
type Row<'a>: RowView<'a>; // GAT
fn query<'a>(&'a self) -> Vec<Self::Row<'a>>;
}
// let repo: Box<dyn Repository> = ...; // Error!
// ✅ Solution: Layered architecture
trait InternalRepo {
type Row<'a>: RowView<'a>; // GAT for internal use
fn query_borrowed<'a>(&'a self) -> Vec<Self::Row<'a>>;
}
trait PublicRepo: Send + Sync {
fn query(&self) -> Vec<RowDto>; // Owned data
}
// Adapter converts borrowed -> owned
impl<T: InternalRepo> PublicRepo for T {
fn query(&self) -> Vec<RowDto> {
self.query_borrowed()
.into_iter()
.map(|row| row.to_dto())
.collect()
}
}
```
### Pattern 3: Static Bound ConflictsDetails
- Skill name
rust-lifetime-complex- Repository
- huiali/rust-skills
- Path
.codex/skills/rust-lifetime-complex/SKILL.md- License
- MIT
- Repo updated
- 9 February 2026
FAQ
What does the Rust Lifetime Complex skill do?
Advanced lifetime expert covering HRTB, GAT, 'static bounds, trait object constraints, type system conflicts, and lifetime elision edge cases.triggers: - lifetime - HRTB - GAT - higher-ranked - 'static - trait object - one type is more general - lifetime conflict--- # Advanced Lifetime and Type System Expert ## Core Question **Why won't this type conversion compile?** The type system's boundaries are often surprising.
How do I install the Rust Lifetime Complex skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add huiali/rust-skills --skill rust-lifetime-complex. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Rust Lifetime Complex popular?
It lives in huiali/rust-skills, which has 49 GitHub stars and 7 forks.
Related skills
Rust Actor
49huiali/rust-skills
Actor model expert covering message passing, state isolation, supervision trees, deadlock prevention, fault tolerance, Actix framework, and Erlang-style concurrency patterns.
Rust Anti Pattern
49huiali/rust-skills
Rust anti-patterns and common mistakes expert. Handles code review issues with clone abuse, unwrap in production, String misuse, index loops, and refactoring guidance.
Rust Async
49huiali/rust-skills
Advanced async patterns expert. Handles Stream processing, backpressure control, select/join operations, cancellation, Future trait implementation, and async runtime optimization.
Rust Linear Type
49huiali/rust-skills
线性类型与资源管理专家。处理 Destructible, 资源清理, RAII, unique object, linear semantics, 线性语义, 资源所有权, 独占语义--- # 线性类型 ## 核心问题 **如何保证资源不被泄漏或被重复释放?** 线性类型语义保证每个资源被精确使用一次。
Rust Learner
49huiali/rust-skills
Rust learning and ecosystem tracking expert covering version updates, new features, RFC tracking, crate updates, best practice evolution, and learning resources.
Rust Macro
49huiali/rust-skills
Macro and procedural metaprogramming expert covering macro_rules!, derive macros, proc-macros, compile-time computation, and code generation patterns.
Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.