Rust Linear Type
线性类型与资源管理专家。处理 Destructible, 资源清理, RAII, unique object, linear semantics, 线性语义, 资源所有权, 独占语义--- # 线性类型 ## 核心问题 如何保证资源不被泄漏或被重复释放? 线性类型语义保证每个资源被精确使用一次。
Install
npx skills add huiali/rust-skills --skill rust-linear-typegit 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-linear-type ~/.claude/skills/rust-linear-typePersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
## 线性类型 vs Rust 所有权
| 特性 | Rust 所有权 | 线性类型 |
|-----|------------|---------|
| 移动语义 | ✓ | ✓ |
| 复制语义 | 可选 | ✗ |
| 析构保证 | Drop | Destructible |
| 借用 | ✓ | ✗ 或受限 |
| 多重所有 | Rc/Arc | ✗ |
Rust 默认不是线性类型,但可以通过模式实现线性语义。
## Destructible Trait
```rust
// 线性类型的核心:Destructible 保证析构
use std::mem::ManuallyDrop;
struct LinearBuffer {
ptr: *mut u8,
size: usize,
}
impl Drop for LinearBuffer {
fn drop(&mut self) {
unsafe {
std::alloc::dealloc(self.ptr, Layout::array::<u8>(self.size).unwrap());
}
}
}
// 防止双重释放
struct SafeLinearBuffer {
inner: ManuallyDrop<LinearBuffer>,
}
impl Drop for SafeLinearBuffer {
fn drop(&mut self) {
// 确保只释放一次
unsafe {
ManuallyDrop::drop(&mut self.inner);
}
}
}
```
## 独占对象模式
```rust
// 确保对象只能被移动,不能被复制
#[derive(Copy, Clone)]
struct FileHandle(u32);
impl FileHandle {
// 私有构造函数,防止外部直接创建
fn from_raw(fd: u32) -> Self {
Self(fd)
}
}
// 包装为线性类型
struct LinearFile {
fd: FileHandle,
}
impl LinearFile {
pub fn open(path: &str) -> Result<Self, std::io::Error> {
// 打开文件,返回线性文件句柄
Ok(LinearFile {
fd: FileHandle::from_raw(0), // 示例
})
}
// consume() 方法消费 self,保证线性使用
pub fn consume(self) -> FileHandle {
self.fd
}
}
```
## 资源令牌模式Details
- Skill name
rust-linear-type- Repository
- huiali/rust-skills
- Path
.codex/skills/rust-linear-type/SKILL.md- License
- MIT
- Repo updated
- 9 February 2026
FAQ
What does the Rust Linear Type skill do?
线性类型与资源管理专家。处理 Destructible, 资源清理, RAII, unique object, linear semantics, 线性语义, 资源所有权, 独占语义--- # 线性类型 ## 核心问题 **如何保证资源不被泄漏或被重复释放?** 线性类型语义保证每个资源被精确使用一次。
How do I install the Rust Linear Type skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add huiali/rust-skills --skill rust-linear-type. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Rust Linear Type 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 Macro
49huiali/rust-skills
Macro and procedural metaprogramming expert covering macro_rules!, derive macros, proc-macros, compile-time computation, and code generation patterns.
Rust Lifetime Complex
49huiali/rust-skills
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.
Rust Middleware
49huiali/rust-skills
Web middleware expert covering request tracking, CORS configuration, rate limiting, authentication guards, compression, and middleware composition patterns.
Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.