Self {
store: Some(store),
index,
- read_buffer: Vec::with_capacity(1024*1024),
+ read_buffer: Vec::with_capacity(1024 * 1024),
current_chunk_idx: 0,
current_chunk_digest: [0u8; 32],
state: AsyncIndexReaderState::NoData,
}
}
-impl<S, I> AsyncRead for AsyncIndexReader<S, I> where
-S: AsyncReadChunk + Unpin + Sync + 'static,
-I: IndexFile + Unpin
+impl<S, I> AsyncRead for AsyncIndexReader<S, I>
+where
+ S: AsyncReadChunk + Unpin + Sync + 'static,
+ I: IndexFile + Unpin,
{
fn poll_read(
self: Pin<&mut Self>,
loop {
match &mut this.state {
AsyncIndexReaderState::NoData => {
- if this.current_chunk_idx >= this.index.index_count() {
+ if this.current_chunk_idx >= this.index.index_count() {
return Poll::Ready(Ok(0));
}
.ok_or(io_format_err!("could not get digest"))?
.clone();
- if digest == this.current_chunk_digest {
+ if digest == this.current_chunk_digest {
this.state = AsyncIndexReaderState::HaveData(0);
continue;
}
Some(store) => store,
None => {
return Poll::Ready(Err(io_format_err!("could not find store")));
- },
+ }
};
let future = async move {
};
this.state = AsyncIndexReaderState::WaitForData(future.boxed());
- },
+ }
AsyncIndexReaderState::WaitForData(ref mut future) => {
match ready!(future.as_mut().poll(cx)) {
Ok((store, mut chunk_data)) => {
this.read_buffer.append(&mut chunk_data);
this.state = AsyncIndexReaderState::HaveData(0);
this.store = Some(store);
- },
+ }
Err(err) => {
return Poll::Ready(Err(io_err_other(err)));
- },
+ }
};
- },
+ }
AsyncIndexReaderState::HaveData(offset) => {
let offset = *offset;
let len = this.read_buffer.len();
buf.len()
};
- buf[0..n].copy_from_slice(&this.read_buffer[offset..offset+n]);
+ buf[0..n].copy_from_slice(&this.read_buffer[offset..(offset + n)]);
if offset + n == len {
this.state = AsyncIndexReaderState::NoData;
this.current_chunk_idx += 1;
}
return Poll::Ready(Ok(n));
- },
+ }
}
}
}