-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to get range working with slice types? #129
Comments
Hello @Palmik |
Hey @Palmik, I understand that it is pretty complex to use, and we would like to rewrite a big part of heed and the db.range(&([0, 1, 2]..[2, 3, 4]))?;
db.range(&(&vec1[..]..&vec2[..]))?; |
I want a delete_prefix, but as there is none I'm trying to use delete_range() but have encountered this issue. // This is the prefix I want to delete
let start_key_slice: &[u8] = id.as_slice();
// Here I make a copy and increment the last byte, so I can make a range
let end_key = id;
end_key.0[end_key.len() - 1] += 1;
let end_key_slice: &[u8] = end_key.as_slice();
// Here I use a let binding to make an owned range so I can reference it
let range = start_key_slice .. end_key_slice;
// And this line gives the error
self.db_event_seen_on_relay()?.delete_range(txn, &range)?; The error is:
|
Hey @mikedilger 👋 I'm sorry for not getting back to you sooner. Here is a possibly better working version in which you use references for the slices in the range: // This is the prefix I want to delete
let start_key_slice: &[u8] = id.as_slice();
// Here I make a copy and increment the last byte, so I can make a range
let end_key = id;
end_key.0[end_key.len() - 1] += 1;
let end_key_slice: &[u8] = end_key.as_slice();
// Here I use a let binding to make an owned range so I can reference it
let range = (&start_key_slice) .. (&end_key_slice);
// And this line gives the error
self.db_event_seen_on_relay()?.delete_range(txn, &range)?; |
Hi all, I'm trying to implement the solution described above and I'm running into the same issue. Here's what I have: let start_key_slice: &[u8] = req.start.as_slice();
let end_key_slice: &[u8] = req.end.as_slice();
let range = (&start_key_slice)..(&end_key_slice);
for entry in self
.db
.range(&txn, &range)
.map_err(|e| Error::msg(e.to_string()))?
{} And here's the error:
I'm sure I'm missing something really basic but I'm not super sure what... any help would be appreciated. |
I'm using (and it works):
|
All the slice types define
EItem = [T]
, since[T]
is not Sized,RangeFrom<&[T]>
(and others) do not implementRangeBounds
.Is there some workaround that I am missing?
My use case is a simple key like
[u8; N]
orVec<u8>
, etc.The text was updated successfully, but these errors were encountered: