Module error

Module error 

Source
Expand description

§Error Handling - Rust Book Chapter 9

This module demonstrates custom error types and error handling patterns from The Rust Book Chapter 9.

§Key Concepts Demonstrated

  1. Custom Error Types with thiserror (Chapter 9.2)

    • Using enums to represent different error conditions
    • Adding context to errors with struct variants
    • Automatic Display implementation via #[error(...)]
  2. Automatic Error Conversion with #[from] (Chapter 9.2)

    • The #[from] attribute implements From<OtherError> automatically
    • Enables using ? operator with different error types
  3. Type Alias for Results (Chapter 9.2)

    • Using type Result<T> = std::result::Result<T, SearchError>
    • Makes function signatures cleaner
  4. Builder Methods with impl Into<T> (Chapter 10.2)

    • Accepting flexible input types that can convert to the target type
    • Makes APIs more ergonomic

§Learning Notes

The thiserror crate is industry standard for libraries because it:

  • Derives std::error::Error automatically
  • Generates helpful Display messages
  • Integrates seamlessly with the ? operator

Compare this to the book’s manual error implementations to see how derive macros reduce boilerplate while maintaining full functionality.

Enums§

SearchError
Custom error type for code search operations.

Type Aliases§

Result
Result type alias for SearchError