Files
continuwuity/src/database/stream/keys_rev.rs
T

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

45 lines
940 B
Rust
Raw Normal View History

use std::pin::Pin;
2024-08-08 17:18:30 +00:00
2024-12-14 21:58:01 -05:00
use conduwuit::Result;
2024-08-08 17:18:30 +00:00
use futures::{
stream::FusedStream,
task::{Context, Poll},
Stream,
};
use super::{slice_longevity, Cursor, State};
use crate::keyval::Key;
2024-08-08 17:18:30 +00:00
pub(crate) struct KeysRev<'a> {
state: State<'a>,
}
impl<'a> From<State<'a>> for KeysRev<'a> {
2025-01-02 05:30:51 +00:00
#[inline]
fn from(state: State<'a>) -> Self { Self { state } }
2024-08-08 17:18:30 +00:00
}
impl<'a> Cursor<'a, Key<'a>> for KeysRev<'a> {
2025-01-02 05:30:51 +00:00
#[inline]
2024-08-08 17:18:30 +00:00
fn state(&self) -> &State<'a> { &self.state }
#[inline]
2024-08-08 17:18:30 +00:00
fn fetch(&self) -> Option<Key<'a>> { self.state.fetch_key().map(slice_longevity) }
#[inline]
2024-08-08 17:18:30 +00:00
fn seek(&mut self) { self.state.seek_rev(); }
}
impl<'a> Stream for KeysRev<'a> {
type Item = Result<Key<'a>>;
fn poll_next(mut self: Pin<&mut Self>, _ctx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Ready(self.seek_and_get())
}
}
impl FusedStream for KeysRev<'_> {
#[inline]
2024-08-08 17:18:30 +00:00
fn is_terminated(&self) -> bool { !self.state.init && !self.state.valid() }
}