/// Write the chunk or stash it. In the closure, write all chunks that can be written now.
Write the chunk or stash it. In the closure, write all chunks that can be written now.
Write the chunk or stash it . In the closure write all chunks that can be written now .
pub fn write_or_stash_chunk(&mut self, chunk_index_in_file: usize, chunk_y_index: usize, chunk: Chunk) -> UnitResult {
        if self.requires_sorting.not() {
            return self.chunk_writer.write_chunk(chunk_y_index, chunk);
        }
        // write this chunk now if possible
        if self.unwritten_chunk_indices.peek() == Some(&chunk_index_in_file){
            self.chunk_writer.write_chunk(chunk_y_index, chunk)?;
            self.unwritten_chunk_indices.next().expect("peeked chunk index is missing");
            // write all pending blocks that are immediate successors of this block
            while let Some((next_chunk_y_index, next_chunk)) = self
                .unwritten_chunk_indices.peek().cloned()
                .and_then(|id| self.pending_chunks.remove(&id))
            {
                self.chunk_writer.write_chunk(next_chunk_y_index, next_chunk)?;
                self.unwritten_chunk_indices.next().expect("peeked chunk index is missing");
            }
        }
        else {
            // the argument block is not to be written now,
            // and all the pending blocks are not next up either,
            // so just stash this block
            self.pending_chunks.insert(chunk_index_in_file, (chunk_y_index, chunk));
        }
        Ok(())
    }
pub fn write_or_stash_chunk ( & mut self , chunk_index_in_file : usize , chunk_y_index : usize , chunk : Chunk ) -> UnitResult { if self . requires_sorting . not ( ) { return self . chunk_writer . write_chunk ( chunk_y_index , chunk ) ; } // write this chunk now if possible if self . unwritten_chunk_indices . peek ( ) == Some ( & chunk_index_in_file ) { self . chunk_writer . write_chunk ( chunk_y_index , chunk ) ? ; self . unwritten_chunk_indices . next ( ) . expect ( " " ) ; // write all pending blocks that are immediate successors of this block while let Some ( ( next_chunk_y_index , next_chunk ) ) = self . unwritten_chunk_indices . peek ( ) . cloned ( ) . and_then ( | id | self . pending_chunks . remove ( & id ) ) { self . chunk_writer . write_chunk ( next_chunk_y_index , next_chunk ) ? ; self . unwritten_chunk_indices . next ( ) . expect ( " " ) ; } } else { // the argument block is not to be written now, // and all the pending blocks are not next up either, // so just stash this block self . pending_chunks . insert ( chunk_index_in_file , ( chunk_y_index , chunk ) ) ; } Ok ( ( ) ) }
Write the chunk or stash it.
Write the chunk or stash it .
&mut self
chunk_index_in_file
usize
chunk_y_index
usize
chunk
Chunk