3 ms·
Fully acknowledge your final paragraphs here, for sure. But in case you're curious... I think that if you wrote for (term, buff) in self.buffers { it shoul
by steveklabnik 7y ago
Fully acknowledge your final paragraphs here, for sure. But in case you're curious...
I think that if you wrote
for (term, buff) in self.buffers {
it should have Just Worked. By iterating over a reference to self.buffers, you iterate over a reference to the contents, which you can't move out of. But iterating over it by value, it should give it to you by value, and you'd be fine. That said, I have not tried it, so there might be some context I'm missing. One nice thing about a strict compiler is that I have to think about the details less, and use the error messages to help me fix any problems I find. But that makes it harder to know how it goes without the compiler...
- atombender 7y agoNo, I tried that! That actually moves the "Cannot move" error to the "self.buffers" use itself. The reason I can't just iterate by value is that I'd be consuming data that is already held by the map. The buffer is defined thus: use bitstream_io::{BigEndian, BitWriter}; struct PostingBuffer<W: io::Write> { bw: BitWriter<W, BigEndian>, // ... } impl PostingBuffer { pub fn get_data(self) -> W { self.bw.into_writer() } } bitstream_io::BitWriter's [1] into_writer consumes itself: pub fn into_writer(self) -> W { self.writer } [1] https://docs.rs/bitstream-io/0.8.2/bitstream_io/write/struct.BitWriter.html https://docs.rs/bitstream-io/0.8.2/bitstream_io/write/struct...
- steveklabnik 7y agoAh, ah, I see now. Yes, right. This is exactly why I couched my last paragraph the way I did, heh.