-
-
Notifications
You must be signed in to change notification settings - Fork 203
Description
For motivation, consider parsing Matrix<T>, where T is the type of the matrix entries. Let's say we have such a parsing function, which requires T : FromStr (because from_str will be used as a subroutine when we parse our matrix).
It will have an error type that looks something like this:
use std::str::FromStr;
enum MatrixParseError<T: FromStr> {
Other,
EntryParseError(T::Err),
}Now we want to use thiserror to derive an Error implementation:
#[derive(Debug, Error)]
enum MatrixParseError<T: FromStr> {
#[error("couldn't parse matrix")]
Other,
#[error("couldn't parse entry: {0}")]
EntryParseError(T::Err),
}Now this will complain that T::Err doesn't necessarily implement Display. Sure, in fact I would even want to put a trait bound like T::Err : Error, not just T::Err : Display.
However, I don't want to put that trait bound on the enum MatrixParseError itself. That would be too restrictive. I want to keep the definition of the enum as is, but then the error implementation impl<T: FromStr> Error for MatrixParseError<T> should put the trait bound T::Err : Error (or Display). Now my questions are:
- Is this somehow possible with
thiserror? - If not, do you think one could add functionality for this?
- Or is there any other recommended path that I should take?
Thank you very much!