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

Implement Index<Range>, Index<RangeFrom>, Index<RangeTo>, Index<RangeFull> #13

Open
Geal opened this issue Jul 17, 2015 · 5 comments
Open

Comments

@Geal
Copy link

Geal commented Jul 17, 2015

Hi!

People are asking for bit level parsing in nom, and to use BitVec, I would need to implement those traits to get the slicing syntax on bit streams.

I see in the code that Index<usize> is already implemented, but there's a big warning. Could you explain what it means?

I can try to implement those, but I wonder if you would accept it (because of that warning)

@Gankra
Copy link
Contributor

Gankra commented Jul 17, 2015

Ah, hehe. The NOPE NOPE NOPE is me being upset that we need to "hack" around the Index trait's design by outputting references to TRUE or FALSE statics. It's workable; just stupid.

@Gankra
Copy link
Contributor

Gankra commented Jul 17, 2015

That said, I don't think you can use indexing for bit-ranges. You can't return an &[u1], you'll have to return an iterator.

@Geal
Copy link
Author

Geal commented Jul 17, 2015

yes, it makes sense. Since nom uses a lot of macros, I just need to trick it into thinking it is a real slice. Maybe by returning a Vec<bool> generated from the specified range?

@Geal
Copy link
Author

Geal commented Jul 17, 2015

I'm not sure adding it to this crate would be worth the trouble if it is only used in nom. But then, my only option is to duplicate the code, since I can't implement the traits on BitVec from another crate :(

@Gankra
Copy link
Contributor

Gankra commented Jul 17, 2015

How would you return a Vec<bool>? Indexing requires that you return a reference.

(hence the desire for IndexGet)

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