-
Notifications
You must be signed in to change notification settings - Fork 52
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
fold's param init func should be FnOnce instead of FnMut #513
Comments
I want to parse something like My current implementation (compile failed): fn data_type_stateful<S>(input: &mut StatefulStream<S>) -> PResult<DataType>
where
S: TokenStream,
{
let init = data_type_stateful_inner(input)?;
repeat(0.., (Token::LBracket, Token::RBracket))
.fold(
move || init,
|mut acc, _| {
acc = DataType::Array(Box::new(acc));
acc
},
)
.parse_next(input)
} The implementation can passed the compilation if I can use it like this: fn data_type_stateful<S>(input: &mut StatefulStream<S>) -> PResult<DataType>
where
S: TokenStream,
{
repeat(0.., (Token::LBracket, Token::RBracket))
.fold_(
data_type_stateful_inner,
|mut acc, _| {
acc = DataType::Array(Box::new(acc));
acc
},
)
.parse_next(input)
} It's even more elegant and more reasonable to combinator style. For the trivial init value, they still can pass |
I'd like to contribute to that if any proposal is accepted. |
So if I understand, you are wanting to initialize the state of your |
Yes
How about add a new API? Although I can't find a good name for that except Current
How to determine if a function is a free function or a fluent function? Why can't the init parameter be a fluent function? That also seems very reasonable. |
My implementation here, just for reference. |
My understanding of the problem is: assume we have 2 parsers A and B, and we want to combine them in the following grammar: |
By embedding |
Mirroring rust-bakery/nom#1742 for consideration
The text was updated successfully, but these errors were encountered: