Skip to content
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

uncons_while should take an item reference #75

Closed
ncalexan opened this issue Jan 5, 2017 · 2 comments
Closed

uncons_while should take an item reference #75

ncalexan opened this issue Jan 5, 2017 · 2 comments

Comments

@ncalexan
Copy link
Contributor

ncalexan commented Jan 5, 2017

I'd like to understand some of the API decisions the library makes. Like in #74 , my motivating use case is to parse a token stream (not a character stream), and my tokens do not implement Copy because they include String data, like:

struct Token {
    Keyword(String),
    ...
}

While implementing RangeStream for a newtype wrapping &'a [Token] (like SliceStream but with item type Token rather item type &'a Token), I've run into the following question. Why does uncons_while take an FnMut(Item) rather than FnMut(&Item) at https://github.com/Marwes/combine/blob/master/src/primitives.rs#L562?

In general, the Rust-y pattern seems to be that predicate filters take references to the elements in their containing collection -- but I'm not an experienced Rust user so I'm probably missing something. Any guidance appreciated.

@Marwes
Copy link
Owner

Marwes commented Jan 6, 2017

Summed together both answers in #74 (comment) since it is more or less the same reason.

@ncalexan
Copy link
Contributor Author

ncalexan commented Jan 6, 2017

Summed together both answers in #74 (comment) since it is more or less the same reason.

Thanks for your very useful answer. I think this can just be closed with a link to #44 (comment) which justifies the ergonomics and a link to #74 (comment) which justifies the performance assumptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants