-
Notifications
You must be signed in to change notification settings - Fork 99
Closed
Description
Over in https://github.com/mozilla/mentat, we're using combine to parse &'a [edn::Value] slices. Here, edn::Value is a generic value type conceptually similar to JSON. What is happening here is not specific to edn::Value, so I'll use T: we're using combine to parse &'a [T] streams.
The error type of such a Parser is combine::primitives::ParseError<&'a [T]>. Now, around
Line 449 in 6f2cec6
| impl<S> StdError for ParseError<S> |
std::error::Error only when the underlying Stream::Range is std::fmt::Display. However, no slice &'a [T] can ever satisfy this trait bound due to rust-lang/rust#39328.
I can think of the following ways to work around this issue:
- wait for the Rust specialization feature to land in stable, so that we can specialize the implementation of
std::error::Errorfor&'a [edn::Value].
Even with specialization, this may not allow to solve the problem, depending on the restrictions on third-party types. - wrap our
&'a [T]streams in a newtype implementingStream, and wrap theStream::Rangetype as well.
I have done this locally; it's not hard, but I expect it to have a non-trivial runtime cost, since all ranges need to be wrapped and unwrapped. I'd be surprised if the compiler could make this zero-cost, but I'd love to be amazed. - add a new function to the
Rangetrait specifically for wrapping or otherwise helping formatRangeinstances.
I doubt this would be difficult, but it would be a breaking API change: existing consumers with non-defaultRangeimplementations would have to add the new method, even if they didn't care about this issue (which they can't have been using without significant effort). - add a new
RangeDisplaytrait incombine, define it for theRangetypes incombine, and expect that in thestd::error::Errorimplementation.
This is the least intrusive solution, but ties allRangeimplementations to a single display format. I think this is okay, though -- it's already the case that&strranges have a single display format.
@Marwes, have you thought about this problem? Is there an alternate approach you can suggest? Would you accept a patch for one of the final two proposed solutions?
Metadata
Metadata
Assignees
Labels
No labels