Rust Core Development
Comprehensive guidance for Rust development across web, CLI, desktop, AI/LLM applications, and systems programming.
Quick Reference Guide
By Task Type
Getting Started
- New Project Setup: Use
scripts/init_rust_project.sh to scaffold a project with best practices
- Core Principles: See references/principles.md for ownership, borrowing, and Rust fundamentals
- Common Errors: See references/common-errors.md for solutions to frequent compiler errors
Writing Code
- Design Patterns: Consult references/patterns.md for builder, newtype, RAII, and other patterns
- Error Handling: See references/error-handling.md for Result, Option, anyhow, and thiserror
- Async Programming: See references/async-patterns.md for Tokio, channels, and concurrency
Domain-Specific Development
- Web APIs: See references/web-frameworks.md for Axum, Actix-web, and Rocket
- AI/LLM: See references/ai-llm.md for OpenAI, Anthropic, Ollama, and RAG
- CLI Tools: See references/cli-tui.md for Clap and Ratatui
- Desktop Apps: See references/desktop-tauri.md for Tauri
- Logging: See references/logging-observability.md for tracing and metrics
Code Quality
- Testing: See references/testing.md for unit, integration, and property-based testing
- Code Review: See references/code-review.md for review checklist and anti-patterns
- Performance: See references/performance.md for profiling and optimization
Project Management
- Dependencies: See references/dependencies.md for Cargo.toml best practices
- Project Structure: See references/project-structure.md for modules and workspaces
- Essential Crates: See references/crates-core.md for commonly used libraries
By Question Type
| Question |
Reference |
| "How do I handle errors?" |
error-handling.md |
| "Which web framework should I use?" |
web-frameworks.md |
| "How do I work with async/await?" |
async-patterns.md |
| "How do I integrate OpenAI/Claude?" |
ai-llm.md |
| "How do I build a CLI?" |
cli-tui.md |
| "How do I create a desktop app?" |
desktop-tauri.md |
| "Why won't this compile?" |
common-errors.md |
| "How do I improve performance?" |
performance.md |
| "How do I add logging?" |
logging-observability.md |
| "How should I name this?" |
naming.md |
| "What are best practices?" |
principles.md |
| "How do I test this?" |
testing.md |
Core Workflows
1. Starting a New Project
Initialize Project
./scripts/init_rust_project.sh my-project
Set Up Development Tools
- Configure linting: Copy
assets/configs/clippy.toml and assets/configs/rustfmt.toml
- Configure security: Copy
assets/configs/deny.toml
- Run audit:
./scripts/audit_dependencies.sh
Add Logging
./scripts/setup_logging.sh
Choose Architecture
- Web API: Consult web-frameworks.md for Axum, Actix-web, or Rocket
- CLI Tool: See cli-tui.md for Clap
- Desktop App: See desktop-tauri.md
- Library: See project-structure.md
2. Implementing Features
Design First
- Review principles.md for ownership and type-driven design
- Check patterns.md for applicable design patterns
- Plan error handling strategy from error-handling.md
Write Code
- Follow naming conventions from naming.md
- Use appropriate patterns and error handling
- Add tracing/logging as you go
Test
- Write unit tests (see testing.md)
- Add integration tests for public APIs
- Consider property-based tests for complex logic
3. Code Review and Refinement
Self-Review
- Run through code-review.md checklist
- Check for common anti-patterns
- Verify error handling
Performance Check
- Profile if performance-critical (see performance.md)
- Benchmark changes with Criterion
- Avoid premature optimization
Security Audit
./scripts/audit_dependencies.sh
Decision Guides
Choosing a Web Framework
Use Axum when:
- Building modern REST/GraphQL APIs
- Want composable middleware (Tower ecosystem)
- Prefer type-driven extractors
- Building microservices
Use Actix-web when:
- Need maximum performance
- Building high-throughput APIs
- Want mature, battle-tested framework
- Familiar with actor model
Use Rocket when:
- Rapid prototyping
- Want batteries-included features
- Smaller team or learning Rust web
- Traditional web application
See web-frameworks.md for detailed comparison and code examples.
Error Handling Strategy
Use anyhow for:
- Applications (binaries)
- Quick prototyping
- Internal tools
- When you need ergonomic error handling with context
Use thiserror for:
- Libraries (public APIs)
- When consumers need to handle specific error cases
- Type-safe error hierarchies
- Production code with well-defined error types
See error-handling.md for patterns and examples.
When to Use Async
Use async/await when:
- I/O-bound operations (network, file system)
- Web servers handling many concurrent requests
- Database connection pooling
- Working with streams of data
Don't use async when:
- CPU-bound operations (use
spawn_blocking instead)
- Simple CLI tools
- Performance isn't critical
- Complexity isn't justified
See async-patterns.md for Tokio patterns and best practices.
Automation Scripts
Available Scripts
scripts/init_rust_project.sh
Initialize a new Rust project with best practices:
- Common dependencies (anyhow, thiserror, serde, tracing)
- Benchmark setup with Criterion
- Optimized release profile
- Proper .gitignore
Usage: ./scripts/init_rust_project.sh my-project [bin|lib]
scripts/audit_dependencies.sh
Audit dependencies for security and licensing:
- Runs cargo-audit for security vulnerabilities
- Runs cargo-deny for license compliance
- Shows outdated dependencies
Usage: ./scripts/audit_dependencies.sh
scripts/setup_logging.sh
Set up tracing-based logging:
- Adds tracing dependencies
- Creates logging module with JSON support
- Provides initialization code
Usage: ./scripts/setup_logging.sh
Configuration Templates
assets/configs/clippy.toml
Clippy linting configuration for strict code quality
assets/configs/rustfmt.toml
Code formatting configuration (100 char width, Unix newlines)
assets/configs/deny.toml
cargo-deny configuration for:
- Security advisory checking
- License compliance (MIT, Apache-2.0, BSD allowed)
- Duplicate dependency detection
- Source verification
Reference Documentation
All reference files provide in-depth guidance on specific topics:
Core Language
- principles.md - Ownership, borrowing, zero-cost abstractions
- patterns.md - Builder, newtype, RAII, iterator, visitor patterns
- error-handling.md - Result, Option, anyhow, thiserror
- naming.md - Rust naming conventions
- common-errors.md - Borrow checker, lifetime errors, solutions
Development
- testing.md - Unit, integration, property-based, benchmarking
- project-structure.md - Modules, workspaces, organization
- dependencies.md - Cargo.toml, features, version management
- performance.md - Profiling, optimization, benchmarking
- code-review.md - Review checklist, anti-patterns
Async & Concurrency
- async-patterns.md - Tokio, futures, streams, channels
Domains
- web-frameworks.md - Axum, Actix-web, Rocket comparison
- ai-llm.md - OpenAI, Anthropic, Ollama, RAG, function calling
- cli-tui.md - Clap, Ratatui, terminal interfaces
- desktop-tauri.md - Desktop apps, plugins, IPC
- logging-observability.md - Tracing, metrics, OpenTelemetry
Libraries
- crates-core.md - Essential crates (serde, tokio, anyhow, reqwest)
When to Consult References
Load references progressively as needed:
- Starting out: Read principles.md to understand Rust fundamentals
- Choosing approach: Consult domain-specific guides (web-frameworks.md, ai-llm.md, etc.)
- Implementing: Reference patterns.md and error-handling.md
- Debugging: Check common-errors.md
- Optimizing: See performance.md
- Reviewing: Use code-review.md checklist
Don't load all references at once—consult them as specific needs arise.
Best Practices Summary
- Embrace the borrow checker - Work with ownership, not against it
- Use type-driven design - Make invalid states unrepresentable
- Handle errors explicitly - Use Result and Option, avoid unwrap()
- Test comprehensively - Unit tests, integration tests, property tests
- Profile before optimizing - Measure, don't guess
- Add structured logging - Use tracing for observability
- Review security - Audit dependencies, validate inputs
- Follow conventions - rustfmt, clippy, naming conventions
- Document public APIs - Doc comments with examples
- Keep it simple - Prefer clarity over cleverness
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: aaronbassett-aaronbassett-marketplace-rust-core3description: Rust Core Development4---56# Rust Core Development78Comprehensive guidance for Rust development across web, CLI, desktop, AI/LLM applications, and systems programming.910## Quick Reference Guide1112### By Task Type1314**Getting Started**15- **New Project Setup**: Use `scripts/init_rust_project.sh` to scaffold a project with best practices16- **Core Principles**: See [references/principles.md](references/principles.md) for ownership, borrowing, and Rust fundamentals17- **Common Errors**: See [references/common-errors.md](references/common-errors.md) for solutions to frequent compiler errors1819**Writing Code**20- **Design Patterns**: Consult [references/patterns.md](references/patterns.md) for builder, newtype, RAII, and other patterns21- **Error Handling**: See [references/error-handling.md](references/error-handling.md) for Result, Option, anyhow, and thiserror22- **Async Programming**: See [references/async-patterns.md](references/async-patterns.md) for Tokio, channels, and concurrency2324**Domain-Specific Development**25- **Web APIs**: See [references/web-frameworks.md](references/web-frameworks.md) for Axum, Actix-web, and Rocket26- **AI/LLM**: See [references/ai-llm.md](references/ai-llm.md) for OpenAI, Anthropic, Ollama, and RAG27- **CLI Tools**: See [references/cli-tui.md](references/cli-tui.md) for Clap and Ratatui28- **Desktop Apps**: See [references/desktop-tauri.md](references/desktop-tauri.md) for Tauri29- **Logging**: See [references/logging-observability.md](references/logging-observability.md) for tracing and metrics3031**Code Quality**32- **Testing**: See [references/testing.md](references/testing.md) for unit, integration, and property-based testing33- **Code Review**: See [references/code-review.md](references/code-review.md) for review checklist and anti-patterns34- **Performance**: See [references/performance.md](references/performance.md) for profiling and optimization3536**Project Management**37- **Dependencies**: See [references/dependencies.md](references/dependencies.md) for Cargo.toml best practices38- **Project Structure**: See [references/project-structure.md](references/project-structure.md) for modules and workspaces39- **Essential Crates**: See [references/crates-core.md](references/crates-core.md) for commonly used libraries4041### By Question Type4243| Question | Reference |44|----------|-----------|45| "How do I handle errors?" | [error-handling.md](references/error-handling.md) |46| "Which web framework should I use?" | [web-frameworks.md](references/web-frameworks.md) |47| "How do I work with async/await?" | [async-patterns.md](references/async-patterns.md) |48| "How do I integrate OpenAI/Claude?" | [ai-llm.md](references/ai-llm.md) |49| "How do I build a CLI?" | [cli-tui.md](references/cli-tui.md) |50| "How do I create a desktop app?" | [desktop-tauri.md](references/desktop-tauri.md) |51| "Why won't this compile?" | [common-errors.md](references/common-errors.md) |52| "How do I improve performance?" | [performance.md](references/performance.md) |53| "How do I add logging?" | [logging-observability.md](references/logging-observability.md) |54| "How should I name this?" | [naming.md](references/naming.md) |55| "What are best practices?" | [principles.md](references/principles.md) |56| "How do I test this?" | [testing.md](references/testing.md) |5758## Core Workflows5960### 1. Starting a New Project61621. **Initialize Project**63 ```bash64 ./scripts/init_rust_project.sh my-project65 ```66672. **Set Up Development Tools**68 - Configure linting: Copy `assets/configs/clippy.toml` and `assets/configs/rustfmt.toml`69 - Configure security: Copy `assets/configs/deny.toml`70 - Run audit: `./scripts/audit_dependencies.sh`71723. **Add Logging**73 ```bash74 ./scripts/setup_logging.sh75 ```76774. **Choose Architecture**78 - **Web API**: Consult [web-frameworks.md](references/web-frameworks.md) for Axum, Actix-web, or Rocket79 - **CLI Tool**: See [cli-tui.md](references/cli-tui.md) for Clap80 - **Desktop App**: See [desktop-tauri.md](references/desktop-tauri.md)81 - **Library**: See [project-structure.md](references/project-structure.md)8283### 2. Implementing Features84851. **Design First**86 - Review [principles.md](references/principles.md) for ownership and type-driven design87 - Check [patterns.md](references/patterns.md) for applicable design patterns88 - Plan error handling strategy from [error-handling.md](references/error-handling.md)89902. **Write Code**91 - Follow naming conventions from [naming.md](references/naming.md)92 - Use appropriate patterns and error handling93 - Add tracing/logging as you go94953. **Test**96 - Write unit tests (see [testing.md](references/testing.md))97 - Add integration tests for public APIs98 - Consider property-based tests for complex logic99100### 3. Code Review and Refinement1011021. **Self-Review**103 - Run through [code-review.md](references/code-review.md) checklist104 - Check for common anti-patterns105 - Verify error handling1061072. **Performance Check**108 - Profile if performance-critical (see [performance.md](references/performance.md))109 - Benchmark changes with Criterion110 - Avoid premature optimization1111123. **Security Audit**113 ```bash114 ./scripts/audit_dependencies.sh115 ```116117## Decision Guides118119### Choosing a Web Framework120121**Use Axum when:**122- Building modern REST/GraphQL APIs123- Want composable middleware (Tower ecosystem)124- Prefer type-driven extractors125- Building microservices126127**Use Actix-web when:**128- Need maximum performance129- Building high-throughput APIs130- Want mature, battle-tested framework131- Familiar with actor model132133**Use Rocket when:**134- Rapid prototyping135- Want batteries-included features136- Smaller team or learning Rust web137- Traditional web application138139See [web-frameworks.md](references/web-frameworks.md) for detailed comparison and code examples.140141### Error Handling Strategy142143**Use `anyhow` for:**144- Applications (binaries)145- Quick prototyping146- Internal tools147- When you need ergonomic error handling with context148149**Use `thiserror` for:**150- Libraries (public APIs)151- When consumers need to handle specific error cases152- Type-safe error hierarchies153- Production code with well-defined error types154155See [error-handling.md](references/error-handling.md) for patterns and examples.156157### When to Use Async158159**Use async/await when:**160- I/O-bound operations (network, file system)161- Web servers handling many concurrent requests162- Database connection pooling163- Working with streams of data164165**Don't use async when:**166- CPU-bound operations (use `spawn_blocking` instead)167- Simple CLI tools168- Performance isn't critical169- Complexity isn't justified170171See [async-patterns.md](references/async-patterns.md) for Tokio patterns and best practices.172173## Automation Scripts174175### Available Scripts176177**`scripts/init_rust_project.sh`**178Initialize a new Rust project with best practices:179- Common dependencies (anyhow, thiserror, serde, tracing)180- Benchmark setup with Criterion181- Optimized release profile182- Proper .gitignore183184Usage: `./scripts/init_rust_project.sh my-project [bin|lib]`185186**`scripts/audit_dependencies.sh`**187Audit dependencies for security and licensing:188- Runs cargo-audit for security vulnerabilities189- Runs cargo-deny for license compliance190- Shows outdated dependencies191192Usage: `./scripts/audit_dependencies.sh`193194**`scripts/setup_logging.sh`**195Set up tracing-based logging:196- Adds tracing dependencies197- Creates logging module with JSON support198- Provides initialization code199200Usage: `./scripts/setup_logging.sh`201202## Configuration Templates203204### `assets/configs/clippy.toml`205Clippy linting configuration for strict code quality206207### `assets/configs/rustfmt.toml`208Code formatting configuration (100 char width, Unix newlines)209210### `assets/configs/deny.toml`211cargo-deny configuration for:212- Security advisory checking213- License compliance (MIT, Apache-2.0, BSD allowed)214- Duplicate dependency detection215- Source verification216217## Reference Documentation218219All reference files provide in-depth guidance on specific topics:220221### Core Language222- **[principles.md](references/principles.md)** - Ownership, borrowing, zero-cost abstractions223- **[patterns.md](references/patterns.md)** - Builder, newtype, RAII, iterator, visitor patterns224- **[error-handling.md](references/error-handling.md)** - Result, Option, anyhow, thiserror225- **[naming.md](references/naming.md)** - Rust naming conventions226- **[common-errors.md](references/common-errors.md)** - Borrow checker, lifetime errors, solutions227228### Development229- **[testing.md](references/testing.md)** - Unit, integration, property-based, benchmarking230- **[project-structure.md](references/project-structure.md)** - Modules, workspaces, organization231- **[dependencies.md](references/dependencies.md)** - Cargo.toml, features, version management232- **[performance.md](references/performance.md)** - Profiling, optimization, benchmarking233- **[code-review.md](references/code-review.md)** - Review checklist, anti-patterns234235### Async & Concurrency236- **[async-patterns.md](references/async-patterns.md)** - Tokio, futures, streams, channels237238### Domains239- **[web-frameworks.md](references/web-frameworks.md)** - Axum, Actix-web, Rocket comparison240- **[ai-llm.md](references/ai-llm.md)** - OpenAI, Anthropic, Ollama, RAG, function calling241- **[cli-tui.md](references/cli-tui.md)** - Clap, Ratatui, terminal interfaces242- **[desktop-tauri.md](references/desktop-tauri.md)** - Desktop apps, plugins, IPC243- **[logging-observability.md](references/logging-observability.md)** - Tracing, metrics, OpenTelemetry244245### Libraries246- **[crates-core.md](references/crates-core.md)** - Essential crates (serde, tokio, anyhow, reqwest)247248## When to Consult References249250**Load references progressively as needed:**2512521. **Starting out**: Read [principles.md](references/principles.md) to understand Rust fundamentals2532. **Choosing approach**: Consult domain-specific guides ([web-frameworks.md](references/web-frameworks.md), [ai-llm.md](references/ai-llm.md), etc.)2543. **Implementing**: Reference [patterns.md](references/patterns.md) and [error-handling.md](references/error-handling.md)2554. **Debugging**: Check [common-errors.md](references/common-errors.md)2565. **Optimizing**: See [performance.md](references/performance.md)2576. **Reviewing**: Use [code-review.md](references/code-review.md) checklist258259Don't load all references at once—consult them as specific needs arise.260261## Best Practices Summary2622631. **Embrace the borrow checker** - Work with ownership, not against it2642. **Use type-driven design** - Make invalid states unrepresentable2653. **Handle errors explicitly** - Use Result and Option, avoid unwrap()2664. **Test comprehensively** - Unit tests, integration tests, property tests2675. **Profile before optimizing** - Measure, don't guess2686. **Add structured logging** - Use tracing for observability2697. **Review security** - Audit dependencies, validate inputs2708. **Follow conventions** - rustfmt, clippy, naming conventions2719. **Document public APIs** - Doc comments with examples27210. **Keep it simple** - Prefer clarity over cleverness273274---275> Converted and distributed by [TomeVault](https://tomevault.io/claim/aaronbassett) — claim your Tome and manage your conversions.276<!-- tomevault:4.0:skill_md:2026-04-13 -->