mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-06-27 00:16:36 +02:00
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
use std::{convert::AsRef, fmt::Debug};
|
|
|
|
use conduit::{implement, Result};
|
|
use futures::{Stream, StreamExt};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::{keyval, keyval::Key, ser, stream};
|
|
|
|
#[implement(super::Map)]
|
|
pub fn keys_from<'a, K, P>(&'a self, from: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
|
where
|
|
P: Serialize + ?Sized + Debug,
|
|
K: Deserialize<'a> + Send,
|
|
{
|
|
self.keys_from_raw(from)
|
|
.map(keyval::result_deserialize_key::<K>)
|
|
}
|
|
|
|
#[implement(super::Map)]
|
|
#[tracing::instrument(skip(self), level = "trace")]
|
|
pub fn keys_from_raw<P>(&self, from: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
|
where
|
|
P: Serialize + ?Sized + Debug,
|
|
{
|
|
let key = ser::serialize_to_vec(from).expect("failed to serialize query key");
|
|
self.raw_keys_from(&key)
|
|
}
|
|
|
|
#[implement(super::Map)]
|
|
pub fn keys_raw_from<'a, K, P>(&'a self, from: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
|
where
|
|
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
|
K: Deserialize<'a> + Send,
|
|
{
|
|
self.raw_keys_from(from)
|
|
.map(keyval::result_deserialize_key::<K>)
|
|
}
|
|
|
|
#[implement(super::Map)]
|
|
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
|
pub fn raw_keys_from<P>(&self, from: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
|
where
|
|
P: AsRef<[u8]> + ?Sized + Debug,
|
|
{
|
|
let opts = super::read_options_default();
|
|
stream::Keys::new(&self.db, &self.cf, opts, Some(from.as_ref()))
|
|
}
|