meilisearch / heed

A fully typed LMDB wrapper with minimum overhead 🐦
https://docs.rs/heed
MIT License
569 stars 52 forks source link

confusion when using the "range" operation #208

Closed SatoKentaNayoro closed 1 year ago

SatoKentaNayoro commented 1 year ago

While attempting to transition the database used in the ord to lmdb. I encountered confusion when using the range operation. When I tried using&([u8; 44][..]..=[u8; 44[..]]): failed deom1, I received the error message the size for values of type [u8] cannot be known at compilation time. Similarly, when I utilized &(&[u8; 44]..=&[u8; 44]): failed demo2, I encountered the error message the trait bound RangeInclusive<&[u8; 44]>: RangeBounds<[u8]> is not satisfied. Eventually, I managed to complete the testing using iter demo. How should I modify my code to address these issues?

SatoKentaNayoro commented 1 year ago

This should work

struct RangeInclusiveArray<const N: usize>([u8; N], [u8; N]);

impl<const N: usize> RangeBounds<[u8]> for RangeInclusiveArray<N> {
    fn start_bound(&self) -> std::ops::Bound<&[u8]> {
        std::ops::Bound::Included(&self.0)
    }

    fn end_bound(&self) -> std::ops::Bound<&[u8]> {
        std::ops::Bound::Included(&self.1)
    }
}
Kerollmops commented 1 year ago

Hey @hxuchen 👋

Is your last post exposing the solution to your problem? Have you found how to do it?

SatoKentaNayoro commented 1 year ago

@Kerollmops 👋 Yes, I built this struct struct RangeInclusiveArray<const N: usize>([u8; N], [u8; N]);, and then implemented the RangeBounds<[u8]> trait for it. It resolved my issue and passed the tests.