diff --git a/Cargo.toml b/Cargo.toml index b1a3191..df53aa3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "zudb-node" version = "0.0.1" edition = "2024" -rust-version = "1.97" +rust-version = "1.98" license = "Apache-2.0" repository = "https://github.com/tamnd/zu-node" authors = ["Tam Nguyen "] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 45d0ca1..76cc5f5 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -3,5 +3,5 @@ # a different build of the same code. Held to the version in # tamnd/zu's toolchains.toml. [toolchain] -channel = "1.97.1" +channel = "1.98.0" components = ["rustfmt", "clippy"] diff --git a/src/frame.rs b/src/frame.rs index 2fe4a1b..adf0120 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -251,18 +251,33 @@ impl Bytes { /// what the words mean is the layout's business and does not change /// on the way. fn extend(&mut self, raw: &[u8]) { + // `as_chunks` hands back arrays rather than slices, so the width + // is in the type and the conversion that used to sit in the + // middle of each line is gone along with the panic it carried. + // A remainder is bytes that are not a whole element, which is a + // caller handing over something that is not this column, and + // dropping it is what `chunks_exact` did too. match self { Bytes::Eight(v) => v.extend( - raw.chunks_exact(8) - .map(|word| u64::from_ne_bytes(word.try_into().expect("eight bytes"))), + raw.as_chunks::<8>() + .0 + .iter() + .copied() + .map(u64::from_ne_bytes), ), Bytes::Four(v) => v.extend( - raw.chunks_exact(4) - .map(|word| u32::from_ne_bytes(word.try_into().expect("four bytes"))), + raw.as_chunks::<4>() + .0 + .iter() + .copied() + .map(u32::from_ne_bytes), ), Bytes::Two(v) => v.extend( - raw.chunks_exact(2) - .map(|word| u16::from_ne_bytes(word.try_into().expect("two bytes"))), + raw.as_chunks::<2>() + .0 + .iter() + .copied() + .map(u16::from_ne_bytes), ), Bytes::One(v) => v.extend_from_slice(raw), Bytes::Offsets(_) => {} diff --git a/src/load.rs b/src/load.rs index 7b49ab4..ca5e0e6 100644 --- a/src/load.rs +++ b/src/load.rs @@ -495,9 +495,12 @@ fn pairs(env: &Env, options: &Object<'_>, rows: u64) -> Result> flat.len() ))); } + // A pair is a pair in the type, so the two indexes below are not + // indexes any more and the odd tail `as_chunks` would hand back + // is already refused above. let mut pairs = Vec::with_capacity(flat.len() / 2); - for (at, edge) in flat.chunks_exact(2).enumerate() { - pairs.push((within(at, edge[0])?, within(at, edge[1])?)); + for (at, &[from, to]) in flat.as_chunks::<2>().0.iter().enumerate() { + pairs.push((within(at, from)?, within(at, to)?)); } return Ok(pairs); }