pub fn mark_chunk_downloaded<ByteBuf>(
        &mut self,
        piece: &Piece<ByteBuf>,
    ) -> Option<ChunkMarkingResult>
    where
        ByteBuf: AsRef<[u8]>,
    {
        let chunk_info = self.lengths.chunk_info_from_received_piece(
            piece.index,
            piece.begin,
            piece.block.as_ref().len() as u32,
        )?;
        let chunk_range = self.lengths.chunk_range(chunk_info.piece_index);
        let chunk_range = self.chunk_status.get_mut(chunk_range).unwrap();
        if chunk_range.all() {
            return Some(ChunkMarkingResult::PreviouslyCompleted);
        }
        chunk_range.set(chunk_info.chunk_index as usize, true);
        debug!(
            "piece={}, chunk_info={:?}, bits={:?}",
            piece.index, chunk_info, chunk_range,
        );

        // TODO: remove me, it's for debugging
        // {
        //     use std::io::Write;
        //     let mut f = std::fs::OpenOptions::new()
        //         .write(true)
        //         .create(true)
        //         .open("/tmp/chunks")
        //         .unwrap();
        //     write!(f, "{:?}", &self.have).unwrap();
        // }

        if chunk_range.all() {
            return Some(ChunkMarkingResult::Completed);
        }
        Some(ChunkMarkingResult::NotCompleted)
    }
// return true if the whole piece is marked downloaded
return true if the whole piece is marked downloaded
return true if the whole piece is marked downloaded
pub fn mark_chunk_downloaded<ByteBuf>(
        &mut self,
        piece: &Piece<ByteBuf>,
    ) -> Option<ChunkMarkingResult>
    where
        ByteBuf: AsRef<[u8]>,
    {
        let chunk_info = self.lengths.chunk_info_from_received_piece(
            piece.index,
            piece.begin,
            piece.block.as_ref().len() as u32,
        )?;
        let chunk_range = self.lengths.chunk_range(chunk_info.piece_index);
        let chunk_range = self.chunk_status.get_mut(chunk_range).unwrap();
        if chunk_range.all() {
            return Some(ChunkMarkingResult::PreviouslyCompleted);
        }
        chunk_range.set(chunk_info.chunk_index as usize, true);
        debug!(
            "piece={}, chunk_info={:?}, bits={:?}",
            piece.index, chunk_info, chunk_range,
        );
        // TODO: remove me, it's for debugging
        // {
        //     use std::io::Write;
        //     let mut f = std::fs::OpenOptions::new()
        //         .write(true)
        //         .create(true)
        //         .open("/tmp/chunks")
        //         .unwrap();
        //     write!(f, "{:?}", &self.have).unwrap();
        // }
        if chunk_range.all() {
            return Some(ChunkMarkingResult::Completed);
        }
        Some(ChunkMarkingResult::NotCompleted)
    }
pub fn mark_chunk_downloaded < ByteBuf > ( & mut self , piece : & Piece < ByteBuf > , ) -> Option < ChunkMarkingResult > where ByteBuf : AsRef < [ u8 ] > , { let chunk_info = self . lengths . chunk_info_from_received_piece ( piece . index , piece . begin , piece . block . as_ref ( ) . len ( ) as u32 , ) ? ; let chunk_range = self . lengths . chunk_range ( chunk_info . piece_index ) ; let chunk_range = self . chunk_status . get_mut ( chunk_range ) . unwrap ( ) ; if chunk_range . all ( ) { return Some ( ChunkMarkingResult :: PreviouslyCompleted ) ; } chunk_range . set ( chunk_info . chunk_index as usize , true ) ; debug ! ( " " piece index chunk_info chunk_range ) ; // TODO: remove me, it's for debugging // { //     use std::io::Write; //     let mut f = std::fs::OpenOptions::new() //         .write(true) //         .create(true) //         .open("/tmp/chunks") //         .unwrap(); //     write!(f, "{:?}", &self.have).unwrap(); // } if chunk_range . all ( ) { return Some ( ChunkMarkingResult :: Completed ) ; } Some ( ChunkMarkingResult :: NotCompleted ) }
return true if the whole piece is marked downloaded
return true if the whole piece is marked downloaded
&mut self
piece
&Piece<ByteBuf>
&mut self
piece
&Piece<ByteBuf>