Files
continuwuity/src/database/map/stream_from.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.9 KiB
Rust
Raw Normal View History

2024-08-08 17:18:30 +00:00
use std::{convert::AsRef, fmt::Debug};
use conduit::{implement, Result};
use futures::stream::{Stream, StreamExt};
use serde::{Deserialize, Serialize};
2024-11-28 05:54:34 +00:00
use crate::{
keyval::{result_deserialize, serialize_key, KeyVal},
stream,
};
2024-08-08 17:18:30 +00:00
/// Iterate key-value entries in the map starting from lower-bound.
///
/// - Query is serialized
/// - Result is deserialized
#[implement(super::Map)]
pub fn stream_from<'a, K, V, P>(&'a self, from: &P) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
where
P: Serialize + ?Sized + Debug,
K: Deserialize<'a> + Send,
V: Deserialize<'a> + Send,
{
2024-11-28 05:54:34 +00:00
self.stream_from_raw(from).map(result_deserialize::<K, V>)
2024-08-08 17:18:30 +00:00
}
/// Iterate key-value entries in the map starting from lower-bound.
///
/// - Query is serialized
/// - Result is raw
#[implement(super::Map)]
#[tracing::instrument(skip(self), level = "trace")]
pub fn stream_from_raw<P>(&self, from: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
2024-08-08 17:18:30 +00:00
where
P: Serialize + ?Sized + Debug,
{
2024-11-28 05:54:34 +00:00
let key = serialize_key(from).expect("failed to serialize query key");
2024-08-08 17:18:30 +00:00
self.raw_stream_from(&key)
}
/// Iterate key-value entries in the map starting from lower-bound.
///
/// - Query is raw
/// - Result is deserialized
#[implement(super::Map)]
pub fn stream_raw_from<'a, K, V, P>(&'a self, from: &P) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
2024-08-08 17:18:30 +00:00
where
P: AsRef<[u8]> + ?Sized + Debug + Sync,
K: Deserialize<'a> + Send,
V: Deserialize<'a> + Send,
{
2024-11-28 05:54:34 +00:00
self.raw_stream_from(from).map(result_deserialize::<K, V>)
2024-08-08 17:18:30 +00:00
}
/// Iterate key-value entries in the map starting from lower-bound.
///
/// - Query is raw
/// - Result is raw
#[implement(super::Map)]
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
2024-08-08 17:18:30 +00:00
pub fn raw_stream_from<P>(&self, from: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
where
P: AsRef<[u8]> + ?Sized + Debug,
{
let opts = super::read_options_default();
stream::Items::new(&self.db, &self.cf, opts, Some(from.as_ref()))
}