mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
io/region: allow stopping foreach_chunk early
Errors returned from the callback stop the loop early.
This commit is contained in:
parent
551056803d
commit
b2d849081d
3 changed files with 6 additions and 4 deletions
|
@ -15,6 +15,7 @@ fn main() -> Result<()> {
|
|||
minedmap::io::region::from_file(args.file.as_path())?.foreach_chunk(
|
||||
|coords, value: fastnbt::Value| {
|
||||
println!("Chunk {:?}: {:#x?}", coords, value);
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
|
|
|
@ -41,14 +41,15 @@ impl RegionProcessor {
|
|||
Ok(chunk) => chunk,
|
||||
Err(err) => {
|
||||
eprintln!("Chunk {:?}: {}", coords, err);
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
match world::layer::top_layer(&chunk, &self.block_types) {
|
||||
Ok(_) => {}
|
||||
Err(err) => println!("{:?}", err),
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue