Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add impls for i128 16-byte integer db conversions
rust nightly has i128/u128 as 16-byte integer types, expected to land into stable at some point in the (near?) future. SQLite's maximum variable-length integer size is 8-bytes, so this needs to be serialized into a blob for storage in the database. Obviously endianness is a concern here; I've opted to use the platform's native endianness rather than a hard-coded BE/LE choice. This is contracted out to i128's `from_bytes`/`to_bytes`, which will take care of the platform-specific endianness for us. The usage of `unsafe` in the call to i128::from_bytes is to avoid a potentially expensive extra allocation and looping over the contents of the vector to copy them to a `[u8; 16]` intermediate. Once [RFC #2000](rust-lang/rfcs#2000) lands in nightly (tracked in [#44580](rust-lang/rust#44580)), [const generics](https://internals.rust-lang.org/t/lang-team-minutes-const-generics/5090) should make it possible to convert the `Vec<u8>` to a fixed-length `[u8; 16]` array in a nicer fashion.
- Loading branch information