-
I have been using a custom span implementation and have issues when working with it. For some reason my code does not compile anymore. Somewhere a The error is triggered in this line. This is the error message: $ cargo test -- --nocapture
error[E0277]: the trait bound `Stream<'_, char, span::Span, _>: From<&str>` is not satisfied
--> crates/parser/src/parser.rs:94:34
|
94 | let res = symbol().parse(i);
| ----- ^ the trait `From<&str>` is not implemented for `Stream<'_, char, span::Span, _>`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `From<T>`:
<Stream<'a, T, std::ops::Range<usize>, Box<(dyn Iterator<Item = (T, std::ops::Range<usize>)> + 'a)>> as From<&'a [T; N]>>
<Stream<'a, T, std::ops::Range<usize>, Box<(dyn Iterator<Item = (T, std::ops::Range<usize>)> + 'a)>> as From<&'a [T]>>
<Stream<'a, T, std::ops::Range<usize>, Box<(dyn Iterator<Item = (T, std::ops::Range<usize>)> + 'a)>> as From<Vec<T>>>
<Stream<'a, T, std::ops::Range<usize>, Box<(dyn Iterator<Item = (T, std::ops::Range<usize>)> + 'a)>> as From<[T; N]>>
<Stream<'a, char, std::ops::Range<usize>, Box<(dyn Iterator<Item = (char, std::ops::Range<usize>)> + 'a)>> as From<&'a str>>
<Stream<'a, char, std::ops::Range<usize>, Box<(dyn Iterator<Item = (char, std::ops::Range<usize>)> + 'static)>> as From<String>>
= note: required because of the requirements on the impl of `Into<Stream<'_, char, span::Span, _>>` for `&str`
note: required by a bound in `parse`
--> /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/chumsky-0.8.0/src/lib.rs:236:12
|
236 | S: Into<Stream<'a, I, <Self::Error as Error<I>>::Span, Iter>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `parse` Any help is appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The reason that this doesn't work is that chumsky doesn't know how to assign instances of your custom span type to characters in the string. As you can see in the impl here, To solve this, you'll need to use i.e: your final code should look like |
Beta Was this translation helpful? Give feedback.
The reason that this doesn't work is that chumsky doesn't know how to assign instances of your custom span type to characters in the string. As you can see in the impl here,
From<&str> for Stream
is only defined for theRange<usize>
span.To solve this, you'll need to use
Stream::from_iter
. It's a relatively simple process, and the existing implementations in the crate should give you an idea of how to use it.i.e: your final code should look like
symbol().parse(Stream::from_iter(...))
.