Skip to main content

tuwunel_database/map/
rev_stream.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::KeyVal, stream};
10
11/// Streams deserialized key-value entries in descending database order.
12///
13/// Each raw pair is decoded with the database deserializer. Any borrowed key or
14/// value must not be retained across another poll of the stream.
15#[implement(super::Map)]
16pub fn rev_stream<'a, K, V>(
17	self: &'a Arc<Self>,
18) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
19where
20	K: Deserialize<'a> + Send,
21	V: Deserialize<'a> + Send,
22{
23	self.rev_raw_stream()
24		.map(keyval::result_deserialize::<K, V>)
25}
26
27/// Streams raw key-value entries in descending database order.
28///
29/// The scan begins at the last key in the column family. Yielded keys and
30/// values borrow cursor storage and must not be retained across another poll.
31#[implement(super::Map)]
32#[tracing::instrument(skip(self), fields(%self), level = "trace")]
33pub fn rev_raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>> + Send {
34	seek_stream::<stream::ItemsRev<'_>, _>(self, Direction::Reverse, None)
35}