Skip to main content

tuwunel_database/map/
rev_keys.rs

1use std::sync::Arc;
2
3use futures::{Stream, StreamExt};
4use rocksdb::Direction;
5use serde::Deserialize;
6use tuwunel_core::{Result, implement};
7
8use super::seek::seek_stream;
9use crate::{keyval, keyval::Key, stream};
10
11/// Streams deserialized keys in descending database order.
12///
13/// Each raw key is decoded with the database deserializer. Any borrowed key
14/// must not be retained across another poll.
15#[implement(super::Map)]
16pub fn rev_keys<'a, K>(self: &'a Arc<Self>) -> impl Stream<Item = Result<Key<'_, K>>> + Send
17where
18	K: Deserialize<'a> + Send,
19{
20	self.rev_raw_keys()
21		.map(keyval::result_deserialize_key::<K>)
22}
23
24/// Streams raw keys in descending database order.
25///
26/// The scan begins at the last key in the column family. Yielded keys borrow
27/// cursor storage and must not be retained across another poll.
28#[implement(super::Map)]
29#[tracing::instrument(skip(self), fields(%self), level = "trace")]
30pub fn rev_raw_keys(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send {
31	seek_stream::<stream::KeysRev<'_>, _>(self, Direction::Reverse, None)
32}