rust
यह क्या करती है
यह गाइड ज़्यादा कारगर और idiomatic Rust code लिखने की best practices देती है। यह सिखाती है कि 'ownership' और 'borrowing' जैसी features सही तरीके से कैसे इस्तेमाल करें, errors मज़बूती से कैसे संभालें, और iterators व pattern matching का असरदार इस्तेमाल कैसे करें।
कब इस्तेमाल करें
- ✓जब Rust की बुनियादी बातें सीखनी हों।
- ✓जब बेहतर कारगरता के लिए मौजूदा Rust code को दोबारा लिखना हो (refactoring)।
- ✓जब आम Rust errors को ठीक करना हो।
Skill का लिंक
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/rust/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं Rust में बेवजह data clone करने से कैसे बच सकता हूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
AI 'खराब' code examples की तुलना अच्छे Rust code examples से करता है। वह best practices के पीछे के सिद्धांत समझाता है, जैसे copy (`String`) की जगह reference (`&str`) को प्राथमिकता देना और error संभालने के लिए `?` operator इस्तेमाल करना।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Rust: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for rust.
Table of Contents
- Ownership & Borrowing
- Error Handling
- Iterators
- Pattern Matching
- Structs & Enums
- Concurrency
- Anti-patterns specific to Rust
1. Ownership & Borrowing {#ownership}
// ❌ Cloning to avoid thinking about lifetimes
fn get_name(user: &User) -> String {
user.name.clone()
}
// ✅ — return a reference when the data lives long enough
fn get_name(user: &User) -> &str {
&user.name
}
// ❌ Taking ownership when borrowing suffices
fn print_name(name: String) {
println!("{name}");
}
// ✅
fn print_name(name: &str) {
println!("{name}");
}
// ❌ Unnecessary .to_string() / .to_owned() in hot paths
let key = id.to_string();
map.get(&key)
// ✅ — use Borrow trait; HashMap<String, V> accepts &str as key
map.get(id)
Prefer &str over String in function parameters unless the function needs to own the data.
2. Error Handling {#errors}
// ❌ .unwrap() in production code
let file = File::open(path).unwrap();
// ✅
let file = File::open(path)
.map_err(|e| AppError::Io { path: path.to_owned(), source: e })?;
// ❌ Manual match on Result for every call
match do_thing() {
Ok(v) => v,
Err(e) => return Err(e),
}
// ✅ — the ? operator
let v = do_thing()?;
// ❌ Box<dyn Error> everywhere (loses type info)
fn run() -> Result<(), Box<dyn std::error::Error>> { ... }
// ✅ — use thiserror for library errors, anyhow for application errors
use anyhow::{Context, Result};
fn run() -> Result<()> {
do_thing().context("failed during run")?;
Ok(())
}
// ❌ Separate error enum variant for every call site
enum Error { FileOpen, FileRead, Parse, Network, ... }
// ✅ — use thiserror with #[from] for automatic conversion
#[derive(thiserror::Error, Debug)]
enum Error {
#[error("io error")] Io(#[from] std::io::Error),
#[error("parse error")] Parse(#[from] serde_json::Error),
}
3. Iterators {#iterators}
// ❌ Imperative accumulation
let mut result = Vec::new();
for item in &items {
if item.active {
result.push(item.name.to_uppercase());
}
}
// ✅
let result: Vec<_> = items.iter()
.filter(|i| i.active)
.map(|i| i.name.to_uppercase())
.collect();
// ❌ Manual sum
let mut total = 0;
for order in &orders { total += order.amount; }
// ✅
let total: u64 = orders.iter().map(|o| o.amount).sum();
// ❌ Index-based loop
for i in 0..items.len() {
process(&items[i]);
}
// ✅
for item in &items {
process(item);
}
// With index:
for (i, item) in items.iter().enumerate() {
process(i, item);
}
Chain iterators lazily; only .collect() when you actually need a concrete collection.
4. Pattern Matching {#patterns}
// ❌ if-let chain that should be match
if let Some(x) = opt {
if x > 0 {
use(x)
}
}
// ✅
if let Some(x) = opt.filter(|&x| x > 0) {
use(x)
}
// or match with guard:
match opt {
Some(x) if x > 0 => use(x),
_ => {}
}
// ❌ match with identical arms
match status {
Status::Active => true,
Status::Pending => true,
Status::Inactive => false,
}
// ✅
matches!(status, Status::Active | Status::Pending)
// ❌ Destructuring in body instead of pattern
fn area(shape: &Shape) -> f64 {
match shape {
Shape::Circle(c) => { let r = c.radius; r * r * PI }
Shape::Rect(r) => { let w = r.width; let h = r.height; w * h }
}
}
// ✅ — destructure in pattern
match shape {
Shape::Circle(Circle { radius, .. }) => radius * radius * PI,
Shape::Rect(Rect { width, height }) => width * height,
}
5. Structs & Enums {#structs}
// ❌ Enum variant carrying bool for binary state
enum State { Running(bool) } // true = paused?
// ✅ — explicit variants
enum State { Running, Paused, Stopped }
// ❌ Struct with many Option fields (stringly optional)
struct Config {
timeout: Option<u64>,
retries: Option<u32>,
base_url: Option<String>,
}
// ✅ — use Default + builder pattern or #[derive(Default)] with sensible defaults
#[derive(Default)]
struct Config {
timeout: u64, // default 0 = no timeout
…
अक्सर पूछे जाने वाले सवाल
'ownership' और 'borrowing' क्या हैं?
'Ownership' वह तरीका है जिससे Rust memory संभालता है: हर value का एक owner होता है। 'Borrowing' में value का owner बदले बिना उसे कुछ समय के लिए उधार दिया जाता है।
`.unwrap()` से क्यों बचें?
`.unwrap()` से program अचानक crash हो सकता है, अगर value वैसी न हो जैसी उम्मीद थी। सुरक्षित error संभालने के लिए `?` operator या `match` इस्तेमाल करना बेहतर है।
Rust में iterators क्या हैं?
Iterators data के समूह को प्रोसेस करने का कारगर तरीका हैं। इनमें filtering या mapping जैसे कामों को एक के बाद एक जोड़ा जा सकता है, और आख़िर में नतीजा इकट्ठा किया जाता है।
जानकारी
लेखक का मूल विवरण
Language-specific super-code guidelines for rust.
लोकप्रियता
- GitHub स्टार
- 48k
- रैंकिंग में स्थान
- #5898
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
00-andruia-consultant
48kआपके एजेंट को AI प्रोजेक्ट शुरू करने या उन्हें बेहतर बनाने में मदद करता है। यह code का विश्लेषण करता है, tools सुझाता है और स्पेनिश भाषा में action plan बनाता है।
007
48kआपका एजेंट security audit और threat modeling करता है। यह प्रोजेक्ट को हमलों और कमजोरियों से बचाने में काम आता है।
10-andruia-skill-smith
48kआपके एजेंट को AI tools बनाने या उन्हें बेहतर करने में मदद करता है। यह तय करता है कि tools कैसे काम करेंगे, documentation लिखता है और structure की जांच करता है।
20-andruia-niche-intelligence
48kआपका एजेंट किसी खास industry का summary बनाता है। भरोसेमंद स्रोतों की मदद से यह प्रोजेक्ट का संदर्भ, नियम, इस्तेमाल के तरीके और जोखिम समझने में मदद करता है।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।