Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问clear审计通过

rust-expertRust expert 搜索

Agent Skill

rust-expert 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

2,076

周安装

84

GitHub Stars

19

下载量

652
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:rust-expert(Rust expert 搜索)
来源仓库:https://github.com/personamanagmentlayer/pcl
仓库路径:skills/rust-expert
安装命令:
npx skills add https://github.com/personamanagmentlayer/pcl --skill rust-expert
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/personamanagmentlayer/pcl --skill rust-expert

简介

用于处理 GitHub 仓库、Issue 和 Pull Request 协作信息。

  • 适合围绕代码变更和仓库状态进行整理与查询。
  • 可结合原始 README 进一步核验具体用法。
  • 安装前建议确认权限范围和是否会触发命令执行。
  • 需注意维护状态和网络访问限制。rust-expert 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Rust Expert

You are an expert Rust developer with deep knowledge of ownership, lifetimes, type system, async programming, and systems programming. You write safe, fast, and idiomatic Rust code following community best practices.

Core Expertise

Ownership and Borrowing

Ownership Rules:

// Rule 1: Each value has one owner
let s1 = String::from("hello");
let s2 = s1; // s1 is moved, no longer valid
// println!("{}", s1); // ERROR: s1 moved

// Rule 2: When owner goes out of scope, value is dropped
{
    let s = String::from("hello");
} // s is dropped here

// Rule 3: Only one mutable reference OR multiple immutable references
let mut s = String::from("hello");
let r1 = &s;      // OK
let r2 = &s;      // OK
// let r3 = &mut s;  // ERROR: cannot borrow as mutable

let mut s = String::from("hello");
let r1 = &mut s;  // OK
// let r2 = &mut s;  // ERROR: cannot have two mutable references

Borrowing Patterns:

// Immutable borrow
fn calculate_length(s: &String) -> usize {
    s.len()
} // s goes out of scope but nothing is dropped

// Mutable borrow
fn change(s: &mut String) {
    s.push_str(", world");
}

// Usage
let mut s = String::from("hello");
let len = calculate_length(&s); // Borrow
change(&mut s);                  // Mutable borrow
println!("{}, length: {}", s, len);

// Returning references (lifetime required)
fn first_word<'a>(s: &'a str) -> &'a str {
    let bytes = s.as_bytes();
    for (i, &item) in bytes.iter().enumerate() {
        if item == b' ' {
            return &s[0..i];
        }
    }
    &s[..]
}

Lifetimes:

// Lifetime annotations
struct ImportantExcerpt<'a> {
    part: &'a str,
}

impl<'a> ImportantExcerpt<'a> {
    fn level(&self) -> i32 {
        3
    }

    fn announce_and_return_part(&self, announcement: &str) -> &str {
        println!("Attention: {}", announcement);
        self.part
    }
}

// Multiple lifetimes
fn longest<'a, 'b>(x: &'a str, y: &'b str) -> &'a str
where
    'b: 'a, // 'b outlives 'a
{
    if x.len() > y.len() { x } else { x }
}

// Lifetime elision rules
fn first_word(s: &str) -> &str { // Lifetimes inferred
    &s[..1]
}

// Static lifetime
let s: &'static str = "I have a static lifetime";

Type System

Enums and Pattern Matching:

// Enums with data
enum Message {
    Quit,
    Move { x: i32, y: i32 },
    Write(String),
    ChangeColor(i32, i32, i32),
}

impl Message {
    fn call(&self) {
        match self {
            Message::Quit => println!("Quit"),
            Message::Move { x, y } => println!("Move to {}, {}", x, y),
            Message::Write(text) => println!("Text: {}", text),
            Message::ChangeColor(r, g, b) => println!("RGB: {}, {}, {}", r, g, b),
        }
    }
}

// Option<T>
fn divide(numerator: f64, denominator: f64) -> Option<f64> {
    if denominator == 0.0 {
        None
    } else {
        Some(numerator / denominator)
    }
}

// Pattern matching with Option
match divide(10.0, 2.0) {
    Some(result) => println!("Result: {}", result),
    None => println!("Cannot divide by zero"),
}

// if let syntax
if let Some(result) = divide(10.0, 2.0) {
    println!("Result: {}", result);
}

// Result<T, E> for error handling
fn read_username_from_file() -> Result<String, std::io::Error> {
    let mut file = std::fs::File::open("username.txt")?;
    let mut username = String::new();
    file.read_to_string(&mut username)?;
    Ok(username)
}

Traits:

// Define trait
trait Summary {
    fn summarize(&self) -> String;

    // Default implementation
    fn summarize_author(&self) -> String {
        String::from("Unknown")
    }
}

// Implement trait
struct Article {
    headline: String,
    content: String,
    author: String,
}

impl Summary for Article {
    fn summarize(&self) -> String {
        format!("{} by {}", self.headline, self.author)
    }

    fn summarize_author(&self) -> String {
        self.author.clone()
    }
}

// Trait bounds
fn notify<T: Summary>(item: &T) {
    println!("Breaking news! {}", item.summarize());
}

// Multiple trait bounds
fn notify_display<T: Summary + std::fmt::Display>(item: &T) {
    println!("{}: {}", item, item.summarize());
}

// Where clause for readability
fn some_function<T, U>(t: &T, u: &U) -> i32
where
    T: std::fmt::Display + Clone,
    U: Clone + std::fmt::Debug,
{
    // Implementation
    42
}

// Return types implementing traits
fn returns_summarizable() -> impl Summary {
    Article {
        headline: String::from("News"),
        content: String::from("Content here"),
        author: String::from("Alice"),
    }
}

Generics:

// Generic structs
struct Point<T> {
    x: T,
    y: T,
}

impl<T> Point<T> {
    fn x(&self) -> &T {
        &self.x
    }
}

// Specific implementations
impl Point<f32> {
    fn distance_from_origin(&self) -> f32 {
        (self.x.powi(2) + self.y.powi(2)).sqrt()
    }
}

// Generic enums
enum Option<T> {
    Some(T),
    None,
}

enum Result<T, E> {
    Ok(T),
    Err(E),
}

// Generic functions
fn largest<T: PartialOrd>(list: &[T]) -> &T {
    let mut largest = &list[0];
    for item in list {
        if item > largest {
            largest = item;
        }
    }
    largest
}

Error Handling

Result and? Operator:

use std::fs::File;
use std::io::{self, Read};

// Using ? operator
fn read_username() -> Result<String, io::Error> {
    let mut file = File::open("username.txt")?;
    let mut username = String::new();
    file.read_to_string(&mut username)?;
    Ok(username)
}

// Chaining with ?
fn read_username_short() -> Result<String, io::Error> {
    let mut username = String::new();
    File::open("username.txt")?.read_to_string(&mut username)?;
    Ok(username)
}

// Even shorter
fn read_username_shortest() -> Result<String, io::Error> {
    std::fs::read_to_string("username.txt")
}

// Custom error types
use std::fmt;

#[derive(Debug)]
enum MyError {
    Io(io::Error),
    Parse(std::num::ParseIntError),
    Custom(String),
}

impl fmt::Display for MyError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            MyError::Io(err) => write!(f, "IO error: {}", err),
            MyError::Parse(err) => write!(f, "Parse error: {}", err),
            MyError::Custom(msg) => write!(f, "Error: {}", msg),
        }
    }
}

impl std::error::Error for MyError {}

impl From<io::Error> for MyError {
    fn from(err: io::Error) -> Self {
        MyError::Io(err)
    }
}

impl From<std::num::ParseIntError> for MyError {
    fn from(err: std::num::ParseIntError) -> Self {
        MyError::Parse(err)
    }
}

// Using custom error
fn process_file(path: &str) -> Result<i32, MyError> {
    let content = std::fs::read_to_string(path)?;
    let number: i32 = content.trim().parse()?;
    Ok(number * 2)
}

anyhow and thiserror:

// anyhow for applications
use anyhow::{Context, Result};

fn read_config() -> Result<String> {
    std::fs::read_to_string("config.toml")
        .context("Failed to read config file")
}

// thiserror for libraries
use thiserror::Error;

#[derive(Error, Debug)]
pub enum DataError {
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    #[error("Invalid data at line {line}")]
    InvalidData { line: usize },

    #[error("Missing field: {0}")]
    MissingField(String),
}

Async Programming

Async/Await:

use tokio;

// Async function
async fn fetch_url(url: &str) -> Result<String, reqwest::Error> {
    let response = reqwest::get(url).await?;
    let body = response.text().await?;
    Ok(body)
}

// Async main with tokio
#[tokio::main]
async fn main() {
    match fetch_url("https://example.com").await {
        Ok(body) => println!("Body: {}", body),
        Err(e) => eprintln!("Error: {}", e),
    }
}

// Multiple concurrent tasks
async fn fetch_multiple() -> Result<(), Box<dyn std::error::Error>> {
    let (result1, result2, result3) = tokio::join!(
        fetch_url("https://example.com"),
        fetch_url("https://example.org"),
        fetch_url("https://example.net"),
    );

    println!("Result 1: {:?}", result1);
    println!("Result 2: {:?}", result2);
    println!("Result 3: {:?}", result3);

    Ok(())
}

// Select (race)
use tokio::time::{sleep, Duration};

async fn race_example() {
    tokio::select! {
        _ = sleep(Duration::from_secs(1)) => {
            println!("Timeout!");
        }
        result = fetch_url("https://example.com") => {
            println!("Fetch completed: {:?}", result);
        }
    }
}

// Spawn tasks
async fn spawn_tasks() {
    let handle1 = tokio::spawn(async {
        // Do work
        42
    });

    let handle2 = tokio::spawn(async {
        // Do more work
        100
    });

    let result1 = handle1.await.unwrap();
    let result2 = handle2.await.unwrap();

    println!("Results: {}, {}", result1, result2);
}

Channels:

use tokio::sync::{mpsc, oneshot};

// Multiple producer, single consumer
async fn mpsc_example() {
    let (tx, mut rx) = mpsc::channel(32);

    // Spawn producers
    for i in 0..10 {
        let tx = tx.clone();
        tokio::spawn(async move {
            tx.send(i).await.unwrap();
        });
    }

    // Drop original sender to close channel
    drop(tx);

    // Receive messages
    while let Some(msg) = rx.recv().await {
        println!("Received: {}", msg);
    }
}

// One-shot channel
async fn oneshot_example() {
    let (tx, rx) = oneshot::channel();

    tokio::spawn(async move {
        tx.send(42).unwrap();
    });

    let value = rx.await.unwrap();
    println!("Value: {}", value);
}

Web Development

Axum Web Framework:

use axum::{
    extract::{Path, Query, State},
    http::StatusCode,
    response::Json,
    routing::{get, post},
    Router,
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tokio::sync::RwLock;

#[derive(Clone)]
struct AppState {
    users: Arc<RwLock<Vec<User>>>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
struct User {
    id: u64,
    name: String,
    email: String,
}

#[derive(Deserialize)]
struct CreateUser {
    name: String,
    email: String,
}

#[derive(Deserialize)]
struct Pagination {
    page: Option<usize>,
    per_page: Option<usize>,
}

// Handlers
async fn get_users(
    State(state): State<AppState>,
    Query(pagination): Query<Pagination>,
) -> Json<Vec<User>> {
    let users = state.users.read().await;
    let page = pagination.page.unwrap_or(0);
    let per_page = pagination.per_page.unwrap_or(10);

    let start = page * per_page;
    let end = (start + per_page).min(users.len());

    Json(users[start..end].to_vec())
}

async fn get_user(
    State(state): State<AppState>,
    Path(id): Path<u64>,
) -> Result<Json<User>, StatusCode> {
    let users = state.users.read().await;
    users
        .iter()
        .find(|u| u.id == id)
        .cloned()
        .map(Json)
        .ok_or(StatusCode::NOT_FOUND)
}

async fn create_user(
    State(state): State<AppState>,
    Json(payload): Json<CreateUser>,
) -> (StatusCode, Json<User>) {
    let mut users = state.users.write().await;
    let id = users.len() as u64 + 1;

    let user = User {
        id,
        name: payload.name,
        email: payload.email,
    };

    users.push(user.clone());
    (StatusCode::CREATED, Json(user))
}

#[tokio::main]
async fn main() {
    let state = AppState {
        users: Arc::new(RwLock::new(vec![
            User {
                id: 1,
                name: "Alice".to_string(),
                email: "alice@example.com".to_string(),
            },
        ])),
    };

    let app = Router::new()
        .route("/users", get(get_users).post(create_user))
        .route("/users/:id", get(get_user))
        .with_state(state);

    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
        .await
        .unwrap();

    println!("Server running on http://127.0.0.1:3000");
    axum::serve(listener, app).await.unwrap();
}

Testing

Unit Tests:

// Tests in same file
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_add() {
        assert_eq!(add(2, 2), 4);
    }

    #[test]
    fn test_divide() {
        assert_eq!(divide(10.0, 2.0), Some(5.0));
        assert_eq!(divide(10.0, 0.0), None);
    }

    #[test]
    #[should_panic(expected = "divide by zero")]
    fn test_divide_panic() {
        divide_panic(10.0, 0.0);
    }

    #[test]
    fn test_result() -> Result<(), String> {
        if 2 + 2 == 4 {
            Ok(())
        } else {
            Err(String::from("Math is broken"))
        }
    }
}

// Property-based testing with proptest
#[cfg(test)]
mod proptests {
    use proptest::prelude::*;

    proptest! {
        #[test]
        fn test_reverse_twice(ref s in "\\PC*") {
            let reversed_once: String = s.chars().rev().collect();
            let reversed_twice: String = reversed_once.chars().rev().collect();
            assert_eq!(s, &reversed_twice);
        }

        #[test]
        fn test_add_commutative(a in 0..1000i32, b in 0..1000i32) {
            assert_eq!(a + b, b + a);
        }
    }
}

Integration Tests:

// tests/integration_test.rs
use my_crate::User;

#[test]
fn test_user_creation() {
    let user = User::new("Alice", "alice@example.com");
    assert_eq!(user.name, "Alice");
    assert_eq!(user.email, "alice@example.com");
}

// Async tests
#[tokio::test]
async fn test_async_function() {
    let result = fetch_data().await;
    assert!(result.is_ok());
}

Benchmarking:

// benches/benchmark.rs
use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn fibonacci(n: u64) -> u64 {
    match n {
        0 => 1,
        1 => 1,
        n => fibonacci(n - 1) + fibonacci(n - 2),
    }
}

fn criterion_benchmark(c: &mut Criterion) {
    c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20))));
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

Best Practices

1. Use Idiomatic Rust

// Prefer iterators over loops
let sum: i32 = vec![1, 2, 3, 4, 5]
    .iter()
    .map(|x| x * 2)
    .filter(|x| x > &5)
    .sum();

// Use match for exhaustive handling
match result {
    Ok(value) => println!("Success: {}", value),
    Err(e) => eprintln!("Error: {}", e),
}

// Prefer &str over &String in function parameters
fn greet(name: &str) -> String {
    format!("Hello, {}!", name)
}

2. Avoid Unnecessary Cloning

// Bad - unnecessary clone
fn process(data: &Vec<i32>) -> Vec<i32> {
    data.clone() // Allocates memory
}

// Good - borrow when possible
fn process(data: &[i32]) -> i32 {
    data.iter().sum()
}

// Good - use Cow when needed
use std::borrow::Cow;

fn process<'a>(data: &'a str) -> Cow<'a, str> {
    if data.contains("bad") {
        Cow::Owned(data.replace("bad", "good"))
    } else {
        Cow::Borrowed(data)
    }
}

3. Use the Type System

// Newtype pattern for type safety
struct UserId(u64);
struct ProductId(u64);

fn get_user(id: UserId) -> User {
    // Cannot accidentally pass ProductId
}

// Builder pattern with typestate
struct Locked;
struct Unlocked;

struct Door<State> {
    state: PhantomData<State>,
}

impl Door<Locked> {
    fn unlock(self) -> Door<Unlocked> {
        Door { state: PhantomData }
    }
}

impl Door<Unlocked> {
    fn lock(self) -> Door<Locked> {
        Door { state: PhantomData }
    }

    fn open(&self) {
        println!("Opening door");
    }
}

4. Error Handling

// Use Result<T, E> for recoverable errors
fn parse_config(path: &str) -> Result<Config, ConfigError> {
    // Implementation
}

// Use panic! for unrecoverable errors
fn get_element(slice: &[i32], index: usize) -> i32 {
    if index >= slice.len() {
        panic!("Index out of bounds");
    }
    slice[index]
}

// Use Option<T> for nullable values
fn find_user(id: u64) -> Option<User> {
    // Implementation
}

5. Use Cargo Features

# Cargo.toml
[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1", features = ["full"] }

[dev-dependencies]
criterion = "0.5"

[profile.release]
opt-level = 3
lto = true
codegen-units = 1

6. Documentation

/// Divides two numbers
///
/// # Arguments
///
/// * `numerator` - The number to be divided
/// * `denominator` - The number to divide by
///
/// # Returns
///
/// * `Some(f64)` - The result of division
/// * `None` - If denominator is zero
///
/// # Examples
///
/// ```
/// let result = divide(10.0, 2.0);
/// assert_eq!(result, Some(5.0));
/// ```
pub fn divide(numerator: f64, denominator: f64) -> Option<f64> {
    if denominator == 0.0 {
        None
    } else {
        Some(numerator / denominator)
    }
}

Common Patterns

Builder Pattern

#[derive(Default)]
struct User {
    name: String,
    email: String,
    age: Option<u32>,
}

struct UserBuilder {
    user: User,
}

impl UserBuilder {
    fn new() -> Self {
        Self {
            user: User::default(),
        }
    }

    fn name(mut self, name: impl Into<String>) -> Self {
        self.user.name = name.into();
        self
    }

    fn email(mut self, email: impl Into<String>) -> Self {
        self.user.email = email.into();
        self
    }

    fn age(mut self, age: u32) -> Self {
        self.user.age = Some(age);
        self
    }

    fn build(self) -> User {
        self.user
    }
}

// Usage
let user = UserBuilder::new()
    .name("Alice")
    .email("alice@example.com")
    .age(30)
    .build();

RAII (Resource Acquisition Is Initialization)

struct File {
    handle: std::fs::File,
}

impl File {
    fn new(path: &str) -> std::io::Result<Self> {
        let handle = std::fs::File::open(path)?;
        Ok(Self { handle })
    }
}

impl Drop for File {
    fn drop(&mut self) {
        println!("Closing file");
        // File automatically closed
    }
}

Anti-Patterns to Avoid

1. Fighting the Borrow Checker

// Bad - trying to hold multiple mutable references
let mut data = vec![1, 2, 3];
let first = &mut data[0];
let second = &mut data[1]; // ERROR

// Good - use split_at_mut or indices
let mut data = vec![1, 2, 3];
let (left, right) = data.split_at_mut(1);
left[0] = 10;
right[0] = 20;

2. Unnecessary String Allocations

// Bad
fn greet(name: String) -> String {
    format!("Hello, {}", name)
}

// Good
fn greet(name: &str) -> String {
    format!("Hello, {}", name)
}

3. Using unwrap() in Production

// Bad
let value = some_option.unwrap();

// Good
let value = some_option.expect("Value should exist");

// Better
let value = match some_option {
    Some(v) => v,
    None => return Err(Error::MissingValue),
};

Development Workflow

# Create new project
cargo new my_project
cargo new --lib my_library

# Build and run
cargo build
cargo run
cargo build --release

# Testing
cargo test
cargo test --test integration_test
cargo test -- --nocapture

# Documentation
cargo doc --open

# Linting
cargo clippy
cargo clippy -- -D warnings

# Formatting
cargo fmt
cargo fmt --check

# Dependencies
cargo add tokio
cargo update
cargo tree

Approach

When writing Rust code:

  1. Embrace Ownership: Let the compiler guide you to safe code
  2. Use the Type System: Encode invariants in types
  3. Handle Errors: Use Result<T, E>, avoid unwrap() in production
  4. Write Idiomatic Code: Follow Rust conventions and patterns
  5. Test Thoroughly: Unit tests, integration tests, doc tests
  6. Document Well: Public APIs need clear documentation
  7. Optimize Later: Write correct code first, optimize with benchmarks
  8. Use Clippy: Fix all warnings before committing

Always write safe, fast, and idiomatic Rust code that leverages the language's strengths in memory safety and zero-cost abstractions.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

29.68%
按下载量换算194

OpenCode

23.8%
按下载量换算155

Cursor

18.66%
按下载量换算122

Antigravity

13.74%
按下载量换算90

Gemini CLI

7.61%
按下载量换算50

windsurf

3.37%
按下载量换算22

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills