From 3f1a9570b5e24913bc1540c1bae8cf19d3b3c782 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 14 Sep 2022 21:28:29 -0700 Subject: [PATCH] Improve table generator failure messages --- generate/src/main.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/generate/src/main.rs b/generate/src/main.rs index 43a249c..f5bdeff 100644 --- a/generate/src/main.rs +++ b/generate/src/main.rs @@ -54,7 +54,10 @@ fn main() { *prev } else { dense.push(chunk); - let new = u8::try_from(chunkmap.len()).unwrap(); + let new = match u8::try_from(chunkmap.len()) { + Ok(byte) => byte, + Err(_) => panic!("exceeded 256 unique chunks"), + }; chunkmap.insert(chunk, new); new } @@ -117,7 +120,10 @@ fn main() { back.copy_from_slice(&chunk[CHUNK / 2..]); dense_to_halfdense.insert( original_pos, - u8::try_from(halfdense.len() / (CHUNK / 2)).unwrap(), + match u8::try_from(halfdense.len() / (CHUNK / 2)) { + Ok(byte) => byte, + Err(_) => panic!("exceeded 256 half-chunks"), + }, ); halfdense.extend_from_slice(&front); halfdense.extend_from_slice(&back); @@ -134,7 +140,10 @@ fn main() { } dense_to_halfdense.insert( original_pos, - u8::try_from(halfdense.len() / (CHUNK / 2) - 1).unwrap(), + match u8::try_from(halfdense.len() / (CHUNK / 2) - 1) { + Ok(byte) => byte, + Err(_) => panic!("exceeded 256 half-chunks"), + }, ); halfdense.extend_from_slice(&next); back = next;