Struct matrix_sdk::event_cache::RoomPagination
source · pub struct RoomPagination { /* private fields */ }
Expand description
An API object to run pagination queries on a super::RoomEventCache
.
Can be created with super::RoomEventCache::pagination()
.
Implementations§
source§impl RoomPagination
impl RoomPagination
sourcepub async fn run_backwards<Until, Break, UntilFuture>(
&self,
batch_size: u16,
until: Until,
) -> Result<Break>where
Until: FnMut(BackPaginationOutcome, TimelineHasBeenResetWhilePaginating) -> UntilFuture,
UntilFuture: Future<Output = ControlFlow<Break, ()>>,
pub async fn run_backwards<Until, Break, UntilFuture>(
&self,
batch_size: u16,
until: Until,
) -> Result<Break>where
Until: FnMut(BackPaginationOutcome, TimelineHasBeenResetWhilePaginating) -> UntilFuture,
UntilFuture: Future<Output = ControlFlow<Break, ()>>,
Starts a back-pagination for the requested number of events.
This automatically takes care of waiting for a pagination token from sync, if we haven’t done that before.
The until
argument is an async closure that returns a ControlFlow
to decide whether a new pagination must be run or not. It’s helpful when
the server replies with e.g. a certain set of events, but we would like
more, or the event we are looking for isn’t part of this set: in this
case, until
returns ControlFlow::Continue
, otherwise it returns
ControlFlow::Break
. until
receives BackPaginationOutcome
as
its sole argument.
§Errors
It may return an error if the pagination token used during back-pagination has disappeared while we started the pagination. In that case, it’s desirable to call the method again.
§Example
To do a single run:
use std::ops::ControlFlow;
use matrix_sdk::event_cache::{
BackPaginationOutcome,
RoomPagination,
TimelineHasBeenResetWhilePaginating
};
let result = room_pagination.run_backwards(
42,
|BackPaginationOutcome { events, reached_start },
_timeline_has_been_reset: TimelineHasBeenResetWhilePaginating| async move {
// Do something with `events` and `reached_start` maybe?
let _ = events;
let _ = reached_start;
ControlFlow::Break(())
}
).await;
sourcepub fn status(&self) -> Subscriber<PaginatorState>
pub fn status(&self) -> Subscriber<PaginatorState>
Returns a subscriber to the pagination status used for the back-pagination integrated to the event cache.
sourcepub fn hit_timeline_start(&self) -> bool
pub fn hit_timeline_start(&self) -> bool
Returns whether we’ve hit the start of the timeline.
This is true if, and only if, we didn’t have a previous-batch token and running backwards pagination would be useless.
sourcepub fn hit_timeline_end(&self) -> bool
pub fn hit_timeline_end(&self) -> bool
Returns whether we’ve hit the end of the timeline.
This is true if, and only if, we didn’t have a next-batch token and running forwards pagination would be useless.
Auto Trait Implementations§
impl Freeze for RoomPagination
impl !RefUnwindSafe for RoomPagination
impl Send for RoomPagination
impl Sync for RoomPagination
impl Unpin for RoomPagination
impl !UnwindSafe for RoomPagination
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CompatExt for T
impl<T> CompatExt for T
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more