]> git.lizzy.rs Git - rust.git/commit
auto merge of #10739 : DaGenix/rust/mut-chunks, r=alexcrichton
authorbors <bors@rust-lang.org>
Sun, 1 Dec 2013 03:46:35 +0000 (19:46 -0800)
committerbors <bors@rust-lang.org>
Sun, 1 Dec 2013 03:46:35 +0000 (19:46 -0800)
commit6616dbf075477a1b66e3760751f27885961017d4
tree83ef4f682debef0f743fa2abd133ca17da3dd4ed
parent7c889a2fb56726d6caf392720b0dfb46be5b7d15
parent2a8dfc3f22e9f2482719fe89d8c8f2aabae8d754
auto merge of #10739 : DaGenix/rust/mut-chunks, r=alexcrichton

mut_chunks() returns an iterator that produces mutable slices. This is the mutable version of the existing chunks() method on the ImmutableVector trait.

EDIT: This uses only safe code now.

PREVIOUSLY:
I tried to get this working with safe code only, but I couldn't figure out how to make that work. Before #8624, the exact same code worked without the need for the transmute() call. With that fix and without the transmute() call, the compiler complains about the call to mut_slice(). I think the issue is that the mutable slice that is returned will live longer than the self parameter since the self parameter doesn't have an explicit lifetime. However, that is the way that the Iterator trait defines the next() method. I'm sure there is a good reason for that, although I don't quite understand why. Anyway, I think the interface is safe, since the MutChunkIter will only hand out non-overlapping pointers and there is no way to get it to hand out the same pointer twice.