Skip to content

Commit

Permalink
docs(topic): Point out value of custom context
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 6, 2024
1 parent 0e7446d commit 85b2859
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/_topic/error.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
//! # Custom Errors
//!
//! Between [`ContextError`], [`Parser::context`], and [`cut_err`],
//! most error needs will likely be met
//! (see [tutorial][chapter_7]).
//! When that isn't the case, you can implement your own error type.
//! A lot can be accomplished with the built-in error tools, like:
//! - [`ContextError`]
//! - [`Parser::context`]
//! - [`cut_err`]
//!
//! The most basic error trait is [`ParserError`].
//! *(see [tutorial][chapter_7])*
//!
//! Most other needs can likely be met by using a custom context type with [`ContextError`] instead
//! of [`StrContext`].
//! This will require implementing a custom renderer.
//!
//! ## `ParserError` Trait
//!
//! When needed, you can also create your own type that implements [`ParserError`].
//!
//! Optional traits include:
//! - [`AddContext`]
//! - [`FromExternalError`]
//!
//! # Example
//! There are multiple strategies for implementing support for [`AddContext`] and [`FromExternalError`]:
//! - Make your error type generic over the context or external error
//! - Require a trait for the context or external error and `Box` it
//! - Make the context an enum like [`StrContext`]
//! - Implement the trait multiple times, one for each concrete context or external error type,
//! allowing custom behavior per type
//!
//! Example:
//!```rust
#![doc = include_str!("../../examples/custom_error.rs")]
//!```
#![allow(unused_imports)]
use crate::combinator::cut_err;
use crate::error::ContextError;
use crate::error::StrContext;
use crate::Parser;
use crate::_tutorial::chapter_7;
use crate::error::AddContext;
Expand Down

0 comments on commit 85b2859

Please sign in to comment.