How to handle range for non-trivial keys? #106
-
Is your feature request related to a problem? Please describe. It is unclear to me how For example, if I wanted to iterate over the prefixed range:
struct HackRange<'a> {
start: &'a [u8],
end: &'a [u8],
}
impl<'a> AsRef<[u8]> for HackRange<'a> {
fn as_ref(&self) -> &[u8] {
// huh? this IS hit!
todo!()
}
}
impl<'a> RangeBounds<[u8]> for HackRange<'a> {
fn start_bound(&self) -> std::ops::Bound<&[u8]> {
Bound::Included(self.start)
}
fn end_bound(&self) -> std::ops::Bound<&[u8]> {
Bound::Excluded(self.end)
}
} Describe the solution you'd like It would be nice to have some kind of manual range function that I could use for this, as I'd like to use it for pagination in a rest API. I sort of want something between Describe alternatives you've considered I could do manual iteration over the whole prefix, which is not great, but maybe fast enough. It feels like I'm probably holding something wrong though! Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
fn main() -> fjall::Result<()> {
let keyspace = fjall::Config::default().open()?;
let partition = keyspace.open_partition("default", Default::default())?;
partition.insert("devices/122/logs/000000AE", "!!!")?;
partition.insert("devices/123/logs/000000AE", "!!!")?;
partition.insert("devices/123/logs/000000AF", "inside")?;
partition.insert("devices/123/logs/000000B0", "inside")?;
partition.insert("devices/123/logs/000000BD", "inside")?;
partition.insert("devices/123/logs/000000BE", "!!!")?;
partition.insert("devices/124/logs/000000AE", "!!!")?;
assert_eq!(
3,
partition
.range("devices/123/logs/000000AF"..="devices/123/logs/000000BD")
.count()
);
Ok(())
} |
Beta Was this translation helpful? Give feedback.
-
Hmm, let me try to make a better repro. My actual data here is |
Beta Was this translation helpful? Give feedback.
range("devices/123/logs/000000AF"..="devices/123/logs/000000BD")
should work fine.