-
Notifications
You must be signed in to change notification settings - Fork 819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type coercion for Input
in 8.0.0
#1799
Comments
I met the same problem today. This isn't possible to implement to Lines 42 to 47 in 2cec1b3
We may want to refactor that by splitting the |
Alternatively, we can add another associated type for the output of Lines 23 to 36 in 2cec1b3
Something like: pub trait Input: Clone + Sized {
// …
type TakeOutput;
fn take(&self, index: usize) -> Self::TakeOutput;
// …
} |
that might make it way more complex. Are there other alternatives? maybe making |
@Hywan Yeah that makes sense why that won't do it. @Geal Another option to the list other than splitting up the pub trait IntoInput {
type Input: Input;
fn into_input(self) -> Self::Input;
}
impl<'a, const N: usize> IntoInput for &'a [u8; N] {
type Input = &'a [u8];
fn into_input(self) -> Self::Input {
self as &[u8]
}
}
impl<T: Input> IntoInput for T {
type Input = T;
fn into_input(self) -> Self::Input {
self
}
}
fn tag<I>(input: I) where I: IntoInput {
let input = input.into_input();
} Or something of the like. Similar to the |
I like this |
Problem
When upgrading from
7.*
to8.0.0
I noticed thattag(b"hello")
now produces an error.This is due to the shift from the
InputLength
trait being implemented fortag
in7.*
https://docs.rs/nom/7.1.3/nom/bytes/complete/fn.tag.htmlTo
tag
must implementInput
in8.0.0
: https://docs.rs/nom/8.0.0/nom/bytes/complete/fn.tag.htmlInterim Solution
A way to fix this in the interim is to coerce the type into
&[u8]
whichInput
is implemented for. i.e.tag(b"hello" as &[u8])
.Possible Fix
Implement
Input
for&[u8; N]
for anyconst N: usize
The text was updated successfully, but these errors were encountered: