binrw icon indicating copy to clipboard operation
binrw copied to clipboard

Add a `multi` helper for reading a slice of args

Open octylFractal opened this issue 2 years ago • 2 comments

This works similarly to count, but takes &[Args] instead of using a length + cloning the same args.

Name might not be the best -- I avoided using the more obvious map as unlike count this is not analogous to the map attribute.

octylFractal avatar Oct 07 '21 17:10 octylFractal

How does compose (as in object composition) sound? (it may or may not make sense in this context, I'm not sure, but it's what came to mind haha)

Skirmisher avatar Oct 07 '21 22:10 Skirmisher

what about for_each?

kitlith avatar Oct 07 '21 22:10 kitlith

It looks like I accidentally superseded this PR by not paying attention 😵‍💫 and writing and committing a similar helper function. The differences between the two appear to be:

  1. This implementation includes a Vec optimisation, but I don’t think it is needed since Vec takes no arguments anyway so wouldn’t be using this helper;
  2. The committed implementation accepts anything that is IntoIterator<Item = Arg>, so it works with slices but also any other thing that is convertible to an iterator;
  3. The committed implementation takes the arguments as a parameter into the helper function, rather than indirectly via args, which is hopefully a little less ‘weird’ than needing to pass a slice in with args_raw.

As such, I am going to close this PR for now. Please feel free to reopen if I have made some mistake. Thanks!

csnover avatar Nov 16 '22 04:11 csnover