Skip to content

Commit 5f3b7cf

Browse files
committed
Use try_into instead of as
1 parent f4e6440 commit 5f3b7cf

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/bit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Bit {
4949

5050
#[cfg(any(feature = "postgres", feature = "sqlx", feature = "diesel"))]
5151
pub(crate) fn from_sql(buf: &[u8]) -> Result<Bit, Box<dyn std::error::Error + Sync + Send>> {
52-
let len = i32::from_be_bytes(buf[0..4].try_into()?) as usize;
52+
let len = i32::from_be_bytes(buf[0..4].try_into()?).try_into()?;
5353
let data = buf[4..4 + (len + 7) / 8].to_vec();
5454

5555
Ok(Bit { len, data })

src/sparsevec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ impl SparseVector {
6969

7070
/// Returns the sparse vector as a `Vec<f32>`.
7171
pub fn to_vec(&self) -> Vec<f32> {
72-
let mut vec = vec![0.0; self.dim as usize];
72+
let mut vec = vec![0.0; self.dim.try_into().unwrap()];
7373
for (i, v) in self.indices.iter().zip(&self.values) {
74-
vec[*i as usize] = *v;
74+
vec[usize::try_from(*i).unwrap()] = *v;
7575
}
7676
vec
7777
}
@@ -81,7 +81,7 @@ impl SparseVector {
8181
buf: &[u8],
8282
) -> Result<SparseVector, Box<dyn std::error::Error + Sync + Send>> {
8383
let dim = i32::from_be_bytes(buf[0..4].try_into()?);
84-
let nnz = i32::from_be_bytes(buf[4..8].try_into()?) as usize;
84+
let nnz = i32::from_be_bytes(buf[4..8].try_into()?).try_into()?;
8585
let unused = i32::from_be_bytes(buf[8..12].try_into()?);
8686
if unused != 0 {
8787
return Err("expected unused to be 0".into());

0 commit comments

Comments
 (0)