rust

Provide Rust code examples for ownership, lifetimes, traits, and error handling.

77|4|Updated Jun 20, 2022
One-click install
npx skills add https://github.com/htlin222/dotfiles --skill rust-htlin222
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust
Source: https://github.com/htlin222/dotfiles/tree/main/claude.symlink/skills/rust
Command: npx skills add https://github.com/htlin222/dotfiles --skill rust-htlin222

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill assists developers in writing safe, performant, and idiomatic Rust code, addressing common challenges related to ownership, lifetimes, and error handling.

Core Features & Use Cases

  • Ownership and Borrowing: Demonstrates correct patterns for managing memory and data access.
  • Lifetime Management: Provides examples of explicit lifetime annotations and their usage.
  • Error Handling: Shows idiomatic Rust error handling using Result and thiserror.
  • Traits and Generics: Illustrates trait definition, implementation, and generic functions with trait bounds.
  • Async Programming: Includes examples of asynchronous Rust using tokio.
  • Testing: Demonstrates unit testing practices in Rust.
  • Use Case: Debugging a complex borrow checker error by analyzing provided code snippets and understanding lifetime annotations.

Quick Start

Use the rust skill to write a function that takes a string slice and returns its length.

Frequently Asked Questions about rust

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix a borrow checker error in Rust when working with ownership and references?

To fix a Rust borrow checker error, you must ensure ownership rules are followed by using references correctly, either as immutable or mutable, to allow safe data access without moving values. This skill provides examples of correct borrowing patterns to resolve these specific compilation errors.

How do I use explicit lifetime annotations in Rust functions?

Explicit Rust lifetime annotations relate the lifetimes of multiple references in function signatures to ensure valid data scopes. This skill demonstrates how to apply lifetime parameters correctly to prevent dangling references during compilation.

What's the best way to handle errors in Rust using Result and thiserror?

The best way to handle Rust errors is using the Result type alongside the thiserror library to define custom error enumerations. This skill shows idiomatic error handling patterns to propagate failures safely and maintainably.

How do I write asynchronous Rust code with tokio?

Writing asynchronous Rust code with tokio involves using async functions and the tokio runtime to execute concurrent tasks efficiently. This skill includes examples of asynchronous programming to build performant and non-blocking applications.

Does this Rust skill cover defining traits and using generics?

Yes, this Rust skill covers traits and generics by illustrating trait definitions, implementations, and generic functions with trait bounds. You get code examples that enable writing reusable and safe abstractions in your applications.

Why do I need explicit lifetime annotations in my Rust structs?

You need explicit lifetime annotations in Rust structs when they hold references, ensuring the referenced data outlives the struct itself. This skill provides examples of managing lifetimes to guarantee memory safety without runtime overhead.