Implement lazy score queries for top, recent and check (#71)

* Use streams and such to have 200 results

* WIP

* display should take a lazy score future

* Introduce a Scores stream so we can lazily load top score requests

* Fit range to len

* Remove debugging

* Simplify from_user with `and_then`
This commit is contained in:
Natsu Kagami 2025-05-13 00:24:20 +02:00 committed by GitHub
parent 8fdd576eb9
commit 87e0a02e1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 482 additions and 200 deletions

View file

@ -14,9 +14,33 @@ const PREV: &str = "youmubot_pagination_prev";
const FAST_NEXT: &str = "youmubot_pagination_fast_next";
const FAST_PREV: &str = "youmubot_pagination_fast_prev";
pub trait CanEdit: Send {
pub trait CanEdit: Send + Sized {
fn get_message(&self) -> impl Future<Output = Result<Message>> + Send;
fn apply_edit(&mut self, edit: CreateReply) -> impl Future<Output = Result<()>> + Send;
fn headers(&self) -> Option<&str> {
None
}
fn with_header(self, header: String) -> impl CanEdit {
WithHeaders(self, header)
}
}
struct WithHeaders<T>(T, String);
impl<T: CanEdit> CanEdit for WithHeaders<T> {
fn get_message(&self) -> impl Future<Output = Result<Message>> + Send {
self.0.get_message()
}
fn apply_edit(&mut self, edit: CreateReply) -> impl Future<Output = Result<()>> + Send {
self.0.apply_edit(edit)
}
fn headers(&self) -> Option<&str> {
Some(&self.1)
}
}
impl<'a> CanEdit for (Message, &'a Context) {