about summary refs log tree commit diff
path: root/util/src
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-26 20:25:20 +0300
committerVika <vika@fireburn.ru>2024-08-26 20:25:20 +0300
commit806f5fbfabd914d27ff3fb2e822e1c3869068859 (patch)
treecc805cfb7ef5af3d7e26075106d2663e5ca2dd67 /util/src
parent14e58b4137f8f77af43cad8b712596c2e1ab7e8a (diff)
downloadkittybox-806f5fbfabd914d27ff3fb2e822e1c3869068859.tar.zst
Set MSRV to 1.75, remove #[async_trait] declarations whenever possible
Axum still uses `async_trait`, let them do whatever they want. I will
no longer be subject to the humiliation of trying to dig through
lifetime errors and unreadable declarations. Also I don't fucking care
about MSRV, I'm not a library. If you don't have modern Rust, get one.
Diffstat (limited to 'util/src')
-rw-r--r--util/src/queue.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/util/src/queue.rs b/util/src/queue.rs
index c880597..edbec86 100644
--- a/util/src/queue.rs
+++ b/util/src/queue.rs
@@ -1,8 +1,11 @@
+use std::future::Future;
 use futures_util::Stream;
 use std::pin::Pin;
 use uuid::Uuid;
 
-#[async_trait::async_trait]
+/// A stream of jobs from the job queue.
+pub type JobStream<J, E> = Pin<Box<dyn Stream<Item = Result<J, E>> + Send>>;
+
 /// A job queue that can store and return jobs.
 pub trait JobQueue<T: JobItem>: Send + Sync + Sized + Clone + 'static {
     /// A type of job object that will be returned by the queue.
@@ -17,13 +20,14 @@ pub trait JobQueue<T: JobItem>: Send + Sync + Sized + Clone + 'static {
     ///
     /// Returns an error if a job queue failed in some way. Having no
     /// items is not a failure, in which case `Ok(None)` is returned.
-    async fn get_one(&self) -> Result<Option<Self::Job>, Self::Error>;
+    #[must_use = "Undone jobs get put back into the queue."]
+    fn get_one(&self) -> impl Future<Output = Result<Option<Self::Job>, Self::Error>> + Send;
     /// Put an item into a job queue, returning its UUID.
-    async fn put(&self, item: &T) -> Result<Uuid, Self::Error>;
+    fn put(&self, item: &T) -> impl Future<Output = Result<Uuid, Self::Error>> + Send;
 
     /*
     /// Check the amount of pending and stuck items in the job queue.
-    async fn len(&self) -> Result<(usize, usize), Self::Error>;
+    fn len(&self) -> impl Future<Output = Result<(usize, usize), Self::Error>> + Send;
     /// Returns whether the job queue has some pending items.
     async fn is_empty(&self) -> Result<bool, Self::Error> {
         Ok(self.len().await?.0 == 0)
@@ -40,10 +44,9 @@ pub trait JobQueue<T: JobItem>: Send + Sync + Sized + Clone + 'static {
     ///
     /// Note that one item may be returned several times if it is not
     /// marked as done.
-    async fn into_stream(self) -> Result<Pin<Box<dyn Stream<Item = Result<Self::Job, Self::Error>> + Send>>, Self::Error>;
+    fn into_stream(self) -> impl Future<Output = Result<JobStream<Self::Job, Self::Error>, Self::Error>> + Send;
 }
 
-#[async_trait::async_trait]
 /// A job description yielded from a job queue.
 ///
 /// # Implementors
@@ -58,7 +61,7 @@ pub trait Job<T: JobItem, Q: JobQueue<T>>: Send + Sync + Sized {
     /// Get the object describing the task itself.
     fn job(&self) -> &T;
     /// Mark the job as done and remove it from the job queue.
-    async fn done(self) -> Result<(), Q::Error>;
+    fn done(self) -> impl Future<Output = Result<(), Q::Error>> + Send;
 }
 
 /// An object describing the job itself, returned as part of a