hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.9K
active users

Marieke

frens, is there a different way to express `(&mut iterator).take(161)`?

(For those who are curious, the above gives me an iterator over the next 161 items without that consuming the iterator. That means that after that scope, I can still work with the iterator.)

I think it's fine, but perhaps there is a method I don't know about that expresses the matter in a more.. explicit way?

@ma3ke clippy suggests .as_mut() for the .take() combinator for Read impls

@ma3ke the zip crate casts to an &mut dyn Read to do this in one spot

@hipsterelectron
good one, may end up doing that little .as_mut() in the end.

@ma3ke The best alternative (which does not really do the same) would probably be Iterator::next_chunk, though that is nightly only. And may blow your stack if it is some big items.

https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.next_chunk
doc.rust-lang.orgIterator in std::iter - RustA trait for dealing with iterators.

@erk yes, I love next_chunk a lot! for other use cases it would fit the bill even better than take, but in my current case I only know how many lines are coming my way at runtime.

moreover, I'm targeting stable for the thingy I'm currently working on.