From 806f5fbfabd914d27ff3fb2e822e1c3869068859 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 26 Aug 2024 20:25:20 +0300 Subject: 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. --- util/Cargo.toml | 2 +- util/src/queue.rs | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'util') diff --git a/util/Cargo.toml b/util/Cargo.toml index 9a6558b..5f32580 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -2,6 +2,7 @@ name = "kittybox-util" version = "0.2.0" edition = "2021" +rust-version = "1.75.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -14,7 +15,6 @@ http = ["dep:http"] [dependencies] serde = { version = "^1.0.170", features = ["derive"] } serde_json = "^1.0.64" -async-trait = "^0.1.50" futures-util = "^0.3.14" uuid = "^1.3.3" url = "2.5.2" 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 = Pin> + Send>>; + /// A job queue that can store and return jobs. pub trait JobQueue: Send + Sync + Sized + Clone + 'static { /// A type of job object that will be returned by the queue. @@ -17,13 +20,14 @@ pub trait JobQueue: 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, Self::Error>; + #[must_use = "Undone jobs get put back into the queue."] + fn get_one(&self) -> impl Future, Self::Error>> + Send; /// Put an item into a job queue, returning its UUID. - async fn put(&self, item: &T) -> Result; + fn put(&self, item: &T) -> impl Future> + 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> + Send; /// Returns whether the job queue has some pending items. async fn is_empty(&self) -> Result { Ok(self.len().await?.0 == 0) @@ -40,10 +44,9 @@ pub trait JobQueue: 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> + Send>>, Self::Error>; + fn into_stream(self) -> impl Future, Self::Error>> + Send; } -#[async_trait::async_trait] /// A job description yielded from a job queue. /// /// # Implementors @@ -58,7 +61,7 @@ pub trait Job>: 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> + Send; } /// An object describing the job itself, returned as part of a -- cgit 1.4.1