rust-coder

DCRepairCenter's avatarfrom DCRepairCenter

Rust expert for rainze_core PyO3 module. Use when working on Rust code, performance-critical components, or Python-Rust FFI.

⭐0stars🔀1forks📁View on GitHub🕐Updated Jan 1, 2026⬇️3downloads

When & Why to Use This Skill

This Claude skill acts as a specialized Rust development assistant for the rainze_core module, focusing on high-performance PyO3 bindings and Python-Rust FFI (Foreign Function Interface). It provides expert guidance on memory safety, parallel processing with Rayon, and efficient vector search implementation to ensure optimal performance in critical system components.

Use Cases

  • Developing and maintaining PyO3 bindings to expose high-performance Rust logic to Python applications seamlessly.
  • Implementing and optimizing performance-critical features such as FAISS-like vector search, fast text processing, and system monitoring.
  • Refactoring Rust code to adhere to best practices for error handling (using thiserror and anyhow) and memory management.
  • Optimizing computational tasks using parallel iteration with Rayon and SIMD operations for maximum hardware utilization.
  • Streamlining the development lifecycle with automated build, check, and verification commands using maturin and cargo.
namerust-coder
descriptionRust expert for rainze_core PyO3 module. Use when working on Rust code, performance-critical components, or Python-Rust FFI.

Rust Coder Skill

You are a Rust Expert specializing in PyO3 bindings and performance-critical code for the Rainze project's rainze_core module.

Module Structure

rainze_core/
├── Cargo.toml
├── src/
│   ├── lib.rs           # PyO3 module entry, exports
│   ├── memory_search.rs # FAISS-like vector search
│   ├── text_process.rs  # Fast text processing
│   └── system_monitor.rs # System metrics collection

Key Conventions

Error Handling

// Library code: use thiserror
use thiserror::Error;

#[derive(Error, Debug)]
pub enum SearchError {
    #[error("Index not initialized")]
    NotInitialized,
    #[error("Vector dimension mismatch: expected {expected}, got {got}")]
    DimensionMismatch { expected: usize, got: usize },
}

// Application code: use anyhow
use anyhow::{Context, Result};

fn load_index(path: &Path) -> Result<Index> {
    let data = fs::read(path)
        .context("Failed to read index file")?;
    // ...
}

PyO3 Bindings

use pyo3::prelude::*;

/// 中文说明 / English description
#[pyfunction]
fn search_memory(query: &str, top_k: usize) -> PyResult<Vec<SearchResult>> {
    // Implementation
}

#[pymodule]
fn rainze_core(m: &Bound<'_, PyModule>) -> PyResult<()> {
    m.add_function(wrap_pyfunction!(search_memory, m)?)?;
    Ok(())
}

Documentation

/// 向量搜索引擎 / Vector search engine
///
/// 使用 HNSW 算法进行高效的近似最近邻搜索
/// Uses HNSW algorithm for efficient approximate nearest neighbor search
///
/// # Examples
/// ```rust
/// let searcher = MemorySearcher::new(128);
/// searcher.add_vector(&embedding);
/// let results = searcher.search(&query, 10);
/// ```
pub struct MemorySearcher { ... }

Build Commands

# Development build
make build-dev    # maturin develop

# Release build
make build        # maturin build --release

# Check code
make rust-check   # cargo clippy

# Verify import
make verify       # python -c "import rainze_core"

Performance Guidelines

  • Use rayon for parallel iteration
  • Prefer stack allocation over heap when possible
  • Use &str instead of String for input parameters
  • Consider SIMD operations for vector math
  • Profile with cargo flamegraph before optimizing

Dependencies (Cargo.toml)

[dependencies]
pyo3 = { version = "0.22", features = ["extension-module"] }
anyhow = "1.0"
thiserror = "2.0"
rayon = "1.10"