io/region: allow stopping foreach_chunk early

Errors returned from the callback stop the loop early.
This commit is contained in:
Matthias Schiffer 2023-02-26 01:01:37 +01:00
parent 551056803d
commit b2d849081d
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
3 changed files with 6 additions and 4 deletions

View file

@ -73,7 +73,7 @@ impl<R: Read + Seek> Region<R> {
where
R: Read + Seek,
T: DeserializeOwned,
F: FnMut(ChunkCoords, T),
F: FnMut(ChunkCoords, T) -> Result<()>,
{
let Region { mut reader } = self;
@ -119,7 +119,7 @@ impl<R: Read + Seek> Region<R> {
let chunk = decode_chunk(&buffer)
.with_context(|| format!("Failed to decode data for chunk {:?}", coords))?;
f(coords, chunk);
f(coords, chunk)?;
}
Ok(())