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

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

45 lines
955 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::{keyval_longevity, Cursor, State};
use crate::keyval::KeyVal;
2024-08-08 17:18:30 +00:00
pub(crate) struct ItemsRev<'a> {
state: State<'a>,
}
impl<'a> From<State<'a>> for ItemsRev<'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, KeyVal<'a>> for ItemsRev<'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 }
2025-01-02 05:30:51 +00:00
#[inline]
2024-08-08 17:18:30 +00:00
fn fetch(&self) -> Option<KeyVal<'a>> { self.state.fetch().map(keyval_longevity) }
#[inline]
2024-08-08 17:18:30 +00:00
fn seek(&mut self) { self.state.seek_rev(); }
}
impl<'a> Stream for ItemsRev<'a> {
type Item = Result<KeyVal<'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 ItemsRev<'_> {
#[inline]
2024-08-08 17:18:30 +00:00
fn is_terminated(&self) -> bool { !self.state.init && !self.state.valid() }
}