Rust Skills

repository·main·Indexed 23 days ago

https://github.com/actionbook/rust-skills

An AI-powered development assistant for Rust that utilizes a meta-cognition framework to provide architectural and domain-aware solutions. It can be used as a Claude Code plugin or as a standalone set of skills for other coding agents. Features include an Agent Cache System for crate and API documentation, dynamic skill generation from Cargo.toml, a three-layer cognitive model for problem solving, and a library of code templates for error handling, concurrency, and FFI.

Tokens
200.5K
Snippets
413
Records
746
Agent score
77%

What's inside rust-skills

  1. Overview of Unsafe Checker rule sections

    main

    The Unsafe Checker organizes its rules into seven distinct sections based on the type of unsafe operation being performed. These sections are categorized by severity level (CRITICAL, HIGH, MEDIUM) and focus area. Rules within a section are identified by a specific prefix.

    #SectionPrefixLevelFocus
    1General Principlesgeneral-CRITICALFoundational unsafe usage guidance
    2Safety Abstractionsafety-CRITICALBuilding sound safe APIs
    3Raw Pointersptr-HIGHPointer manipulation safety
    4Unionunion-HIGHUnion type safety
    5Memory Layoutmem-HIGHData representation correctness
    6FFIffi-CRITICALC interoperability safety
    7I/O Safetyio-MEDIUMHandle/resource safety
  2. Overview of Rust Code Templates

    main
    Rust Skills provides ready-to-use code templates for common Rust patterns. These templates are designed to follow established coding guidelines and best practices, covering areas such as error handling, concurrency, FFI, testing, and project scaffolding.
  3. Use the Unsafe Rust Checker skill

    main

    The unsafe-checker skill is a critical tool for reviewing unsafe Rust code and FFI (Foreign Function Interface) implementations. It triggers on keywords and concepts related to memory safety and low-level operations, including unsafe, raw pointer, FFI, transmute, *mut, *const, union, #[repr(C)], libc, std::ffi, MaybeUninit, NonNull, and discussions regarding soundness or undefined behavior (UB).

    globs: ["**/*.rs"]
    allowed-tools: ["Read", "Grep", "Glob"]
  4. Understand the three functional categories of Rust-Skills

    main

    Rust-Skills categorizes its capabilities into three main types to improve how Claude Code interacts with Rust development:

    1. Meta-Cognition (元认知类): Enhances semantic recognition to trace problems from surface-level errors (like compiler errors) to their underlying architectural or domain-specific causes.
    2. Dynamic Skills (动态 Skills 类): Enables on-demand generation and hot-loading of skills for specific crates, ensuring the AI has up-to-date knowledge of the vast Rust ecosystem.
    3. Info Fetching (信息获取类): Provides mechanisms to fetch the latest information to keep pace with the evolving Rust landscape.
  5. Core Capabilities of Rust-Skills

    main

    Rust-Skills provides several advanced features for Rust development:

    • Dynamic Skill Generation: Automatically generates crate-specific skills by analyzing Cargo.toml dependencies.
    • Background Research Agents: 8 specialized agents perform real-time data retrieval in the background without blocking the user conversation.
    • Comprehensive Unsafe Auditing: Includes 47 rules covering memory safety, FFI, concurrency, and documentation standards.
    • Bilingual Support: Supports over 400 trigger keywords in both Chinese and English.
  6. View the Agents Index

    main
    The Agents Index provides an auto-generated overview of all available agents within the system. It lists the agent name, the underlying model used (e.g., haiku), the number of tools assigned to it, and its primary purpose. This index is useful for identifying which agent to use for specific tasks like fetching URLs, researching crates, or accessing documentation caches.
  7. What is a Skill in rust-skills?

    main

    In rust-skills, a Skill is not a knowledge database, documentation, or a collection of code snippets. Instead, it is a Cognitive Protocol designed to shape how an AI (like Claude) thinks about a problem rather than just providing facts.

    A Skill transforms a surface-level symptom (like a compiler error) into a deeper design question. While a knowledge base might tell you that E0382 means a value was moved, a Skill forces the reasoning process to ask: "Is this ownership design intentional?"

    Key Differences

    AspectKnowledge BaseSkill
    ContainsFacts, answersProtocols, frameworks
    ProvidesWhat to doHow to think
    OutputSolutionsReasoning processes
    Value-addRecallJudgment
  8. Avoid mutability anti-patterns in Rust

    main

    To maintain performance and safety, avoid these common mutability mistakes:

    Anti-PatternWhy BadBetter
    RefCell everywhereRuntime panicsClear ownership design
    Mutex for single-threadUnnecessary overheadRefCell
    Ignore RefCell panicHard to debugHandle or restructure
    Lock inside hot loopPerformance killerBatch operations
  9. Handle Options and Results with combinators

    main

    Instead of manual pattern matching, use combinators to transform or handle Option and Result values:

    Option Handling

    • ok_or: Converts an Option<T> to a Result<T, E> using a static error value.
    • ok_or_else: Converts an Option<T> to a Result<T, E> using a closure (useful for dynamic error messages).
    • and_then: Chains operations that return an Option (equivalent to flatMap).

    Result Combinators

    • map: Transforms the success value inside a Result.
    • map_err: Transforms the error value inside a Result.
    • and_then: Chains operations that return a Result.
    • unwrap_or: Provides a default value if the result is Err or None.
    • unwrap_or_else: Provides a default value via a closure if the result is Err or None.
    • unwrap_or_default: Uses the type's Default implementation if the result is Err or None.
    // Converting Option to Result
    fn get_user(id: u32) -> Result<User, &'static str> {
        find_user(id).ok_or("user not found")
    }
    
    fn get_user_dynamic(id: u32) -> Result<User, String> {
        find_user(id).ok_or_else(|| format!("user {} not found", id))
    }
    
    // Result Combinators
    fn parse_port(s: &str) -> Result<u16, ParseError> {
        s.parse::<u16>().map_err(|e| ParseError::InvalidPort(e))
    }
    
    let port = config.port().unwrap_or(8080);
    let port = config.port().unwrap_or_else(|| find_free_port());
  10. Mental models for core Rust concepts

    main

    When learning or explaining Rust, use these mental models and analogies to build intuition for how the language manages memory and safety:

    ConceptMental ModelAnalogy
    OwnershipUnique keyOnly one person has the house key
    MoveKey handoverGiving away your key
    &TLending for readingLending a book
    &mut TExclusive editingOnly you can edit the doc
    Lifetime 'aValid scope"Ticket valid until..."
    Box<T>Heap pointerRemote control to TV
    Rc<T>Shared ownershipMultiple remotes, last turns off
    Arc<T>Thread-safe RcRemotes from any room
  11. FFI Error Handling Patterns

    main

    Choose an error handling pattern based on your API requirements:

    PatternUsage
    Return codeSimple success/failure (e.g., returning 0 for success and non-zero for error)
    Return code + out paramReturn a status code and use a pointer to provide the actual result on success
    errnoFollow POSIX-style APIs by setting the global errno on error
    Error message functionProvide a separate function to retrieve a string describing the last error
    Last-error thread-localFollow Windows-style APIs by storing error state in thread-local storage
  12. How the core-actionbook skill works

    main

    The core-actionbook skill provides pre-computed action manuals for browser automation. Instead of agents parsing raw HTML, they use this skill to receive structured page information, including DOM structures and specific element selectors.

    Note: This is an internal support skill. It is user-invocable: false and should only be used when another rust-skills workflow explicitly requests actionbook-backed selectors.