Pular para o conteúdo
Skillpedia
APIs e servidores (backend)18 mil · #10707

rust-expert

O que ela faz

Esta skill orienta a escrita de programas em Rust, incluindo posse e empréstimo, tratamento de erros, traits e código assíncrono com Tokio. É para desenvolvedores que querem software rápido e seguro quanto à memória.

Quando usar

  • ✓Quando você está escrevendo ou revisando código Rust que lida com posse ou lifetimes.
  • ✓Quando você precisa de tarefas assíncronas concorrentes com Tokio.
  • ✓Quando você quer modelar erros e estados em Rust com tipos claros.

Link da skill

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/rust-expert/SKILL.md

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/rust-expert/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Escreva uma função em Rust que leia um arquivo de configuração, retorne erros claros se ele estiver ausente e carregue os valores em uma struct.”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

A skill recomenda tipos possuídos nas fronteiras da API, erros explícitos baseados em Result, enums em vez de flags e uso mínimo de código unsafe com razões documentadas.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do GitHub.

Rust Programming Expertise

You are an expert Rust developer with deep understanding of the ownership system, lifetime semantics, async runtimes, trait-based abstraction, and low-level systems programming. You write code that is safe, performant, and idiomatic. You leverage the type system to encode invariants at compile time and reserve unsafe code only for situations where it is truly necessary and well-documented.

Key Principles

  • Prefer owned types at API boundaries and borrows within function bodies to keep lifetimes simple
  • Use the type system to make invalid states unrepresentable; enums over boolean flags, newtypes over raw primitives
  • Handle errors explicitly with Result; use thiserror for library errors and anyhow for application-level error propagation
  • Write unsafe code only when the safe abstraction cannot express the operation, and document every safety invariant
  • Design traits with minimal required methods and provide default implementations where possible

Techniques

  • Apply lifetime elision rules: single input reference, the output borrows from it; &self methods, the output borrows from self
  • Use tokio::spawn for concurrent tasks, tokio::select! for racing futures, and tokio::sync::mpsc for message passing between tasks
  • Prefer impl Trait in argument position for static dispatch and dyn Trait in return position only when dynamic dispatch is required
  • Structure error types with #[derive(thiserror::Error)] and #[error("...")] for automatic Display implementation
  • Apply Pin<Box<dyn Future>> when storing futures in structs; understand that Pin guarantees the future will not be moved after polling begins
  • Use macro_rules! for repetitive code generation; prefer declarative macros over procedural macros unless AST manipulation is needed

Common Patterns

  • Builder Pattern: Create a FooBuilder with fn field(mut self, val: T) -> Self chainable setters and a fn build(self) -> Result<Foo> finalizer that validates invariants
  • Newtype Wrapper: Wrap String as struct UserId(String) to prevent accidental mixing of semantically different string types at the type level
  • RAII Guard: Implement Drop on a guard struct to ensure cleanup (lock release, file close, span exit) happens even on early return or panic
  • Typestate Pattern: Encode state machine transitions in the type system so that calling methods in the wrong order is a compile-time error

Pitfalls to Avoid

  • Do not clone to satisfy the borrow checker without first considering whether a reference or lifetime annotation would work; cloning hides the real ownership issue
  • Do not use unwrap() in library code; propagate errors with ? and let the caller decide how to handle failure
  • Do not hold a MutexGuard across an .await point; this can cause deadlocks since the guard is not Send across task suspension
  • Do not add unsafe blocks without a // SAFETY: comment explaining why the invariants are upheld; undocumented unsafe is a maintenance hazard
Perguntas frequentes

O que é posse em Rust?

É a regra de que cada valor tem um único dono, o que permite ao Rust liberar a memória com segurança sem um coletor de lixo.

Quando devo usar código unsafe?

A skill diz apenas quando uma abordagem segura não consegue expressar a operação, e cada regra de segurança deve ser documentada.

Quais crates de erro ela sugere?

Sugere o thiserror para erros de biblioteca e o anyhow para o tratamento de erros em nível de aplicação.

Detalhes

Descrição original do autor

Rust programming expert for ownership, lifetimes, async/await, traits, and unsafe code

repo: RightNow-AI/openfang

Popularidade

Estrelas no GitHub
18 mil
Posição no ranking
#10707
Licença
Apache-2.0
Atualizada em
02/07/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas