一键导入
rust-error-handling
// Rust-specific error handling patterns, building on the base error handling skill. Demonstrates the 'extends' composition feature.
// Rust-specific error handling patterns, building on the base error handling skill. Demonstrates the 'extends' composition feature.
Build terminal UIs with Charmbracelet (Bubble Tea, Lip Gloss, Gum). Use when: Go TUI, shell prompts/spinners, "make CLI prettier", adaptive layouts, async rendering, focus state machines, sparklines, heatmaps, kanban boards, SSH apps.
Foundation for error handling patterns. This is a base skill designed to be extended by language-specific error handling skills.
Common logging patterns and practices. This skill is designed to be included in composite skills via the 'includes' feature.
A comprehensive skill for Rust development that combines error handling, testing, and logging patterns. Demonstrates the 'includes' composition feature by merging content from multiple standalone skills.
Common testing patterns and practices. This skill is designed to be included in composite skills via the 'includes' feature.
Craft professional README.md files for GitHub open source projects. Generates hero sections, installation instructions, feature tables, and architecture diagrams. Use when creating or revising a README, documenting a CLI tool, library, or open source project, or when user asks about README structure, badges, or project documentation.
| id | rust-error-handling |
| name | Rust Error Handling |
| description | Rust-specific error handling patterns, building on the base error handling skill. Demonstrates the 'extends' composition feature. |
| tags | ["error-handling","rust","example"] |
| extends | error-handling-base |
Rust-specific error handling patterns that extend the base error handling skill.
thiserror for defining library error typesanyhow for application-level error handlingstd::error::Error trait for custom error types? operator for ergonomic error propagationResult<T, E> over panicking for recoverable errorsunwrap() only in tests or when failure is impossible// Define library errors with thiserror
use thiserror::Error;
#[derive(Error, Debug)]
pub enum ConfigError {
#[error("failed to read config file: {0}")]
Io(#[from] std::io::Error),
#[error("invalid config format: {0}")]
Parse(#[from] toml::de::Error),
#[error("missing required field: {field}")]
MissingField { field: String },
}
// Application-level error handling with anyhow
use anyhow::{Context, Result};
fn load_config(path: &str) -> Result<Config> {
let content = std::fs::read_to_string(path)
.with_context(|| format!("failed to read config from {}", path))?;
let config: Config = toml::from_str(&content)
.context("failed to parse config TOML")?;
Ok(config)
}
thiserror deriveanyhow::Contextunwrap() calls in production code pathsResult is used instead of panic! for recoverable errors