Remove the panics and unwraps

This commit is contained in:
Clément Renault
2023-11-23 14:47:56 +01:00
parent 0dbf1a16ff
commit 58dac8af42
7 changed files with 41 additions and 26 deletions

View File

@ -10,7 +10,11 @@ impl<'a> heed::BytesDecode<'a> for ScriptLanguageCodec {
type DItem = (Script, Language);
fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, BoxedError> {
let sep = bytes.iter().position(|b| *b == 0).unwrap();
let sep = bytes
.iter()
.position(|b| *b == 0)
.ok_or("cannot find nul byte")
.map_err(BoxedError::from)?;
let (s_bytes, l_bytes) = bytes.split_at(sep);
let script = str::from_utf8(s_bytes)?;
let script_name = Script::from_name(script);