Skip to content

Commit

Permalink
Impl std::error::Error for VerboseError
Browse files Browse the repository at this point in the history
Users of rust libraries usually expect error types to implement the
`std::error::Error` trait, and many error utilities will naturally only
work with types implementing that trait. However, unless nom's custom
`Error` type, the `VerboseError` did not implement the std trait.

This change introduces an empty implementation, meaning that users will
only benefit from `Display` and `Debug` in the end.
  • Loading branch information
neithernut authored and Geal committed Jan 23, 2021
1 parent ab01f04 commit 56c0b1a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ impl<I: fmt::Display> fmt::Display for VerboseError<I> {
}
}

#[cfg(feature = "std")]
impl<I: fmt::Debug + fmt::Display> std::error::Error for VerboseError<I> {}

use crate::internal::{Err, IResult};

/// Create a new error from an input position, a static string and an existing error.
Expand Down

0 comments on commit 56c0b1a

Please sign in to comment.