mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-10-11 22:26:25 +00:00
Remove the panics and unwraps
This commit is contained in:
@@ -63,7 +63,7 @@ where
|
||||
v.extend_from_slice(&value.field_id.to_be_bytes());
|
||||
v.extend_from_slice(&[value.level]);
|
||||
|
||||
let bound = T::bytes_encode(&value.left_bound).unwrap();
|
||||
let bound = T::bytes_encode(&value.left_bound)?;
|
||||
v.extend_from_slice(&bound);
|
||||
|
||||
Ok(Cow::Owned(v))
|
||||
|
@@ -12,10 +12,10 @@ impl<'a> BytesDecode<'a> for OrderedF64Codec {
|
||||
|
||||
fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, BoxedError> {
|
||||
if bytes.len() < 16 {
|
||||
panic!() // TODO don't panic
|
||||
Err(BoxedError::from("invalid slice length"))
|
||||
} else {
|
||||
bytes[8..].try_into().map(f64::from_be_bytes).map_err(Into::into)
|
||||
}
|
||||
let f = bytes[8..].try_into().ok().map(f64::from_be_bytes).unwrap();
|
||||
Ok(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ impl heed::BytesEncode<'_> for OrderedF64Codec {
|
||||
let mut buffer = [0u8; 16];
|
||||
|
||||
// write the globally ordered float
|
||||
let bytes = f64_into_bytes(*f).unwrap();
|
||||
let bytes = f64_into_bytes(*f)
|
||||
.ok_or_else(|| BoxedError::from("cannot generate a globally ordered float"))?;
|
||||
buffer[..8].copy_from_slice(&bytes[..]);
|
||||
// Then the f64 value just to be able to read it back
|
||||
let bytes = f.to_be_bytes();
|
||||
|
Reference in New Issue
Block a user