about summary refs log tree commit diff
path: root/src/database/mod.rs
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 /src/database/mod.rs
parent14e58b4137f8f77af43cad8b712596c2e1ab7e8a (diff)
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 'src/database/mod.rs')
-rw-r--r--src/database/mod.rs51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/database/mod.rs b/src/database/mod.rs
index 3b13cb3..058fc0c 100644
--- a/src/database/mod.rs
+++ b/src/database/mod.rs
@@ -1,7 +1,6 @@
 #![warn(missing_docs)]
-use std::borrow::Cow;
+use std::{borrow::Cow, future::Future};
 
-use async_trait::async_trait;
 use kittybox_util::MentionType;
 
 mod file;
@@ -54,7 +53,7 @@ pub mod settings {
     /// **Note**: this trait is sealed to prevent external
     /// implementations, as it wouldn't make sense to add new settings
     /// that aren't used by Kittybox itself.
-    pub trait Setting<'de>: private::Sealed + std::fmt::Debug + Default + Clone + serde::Serialize + serde::de::DeserializeOwned + /*From<Settings> +*/ Send + Sync {
+    pub trait Setting: private::Sealed + std::fmt::Debug + Default + Clone + serde::Serialize + serde::de::DeserializeOwned + /*From<Settings> +*/ Send + Sync + 'static {
         /// The data that the setting carries.
         type Data: std::fmt::Debug + Send + Sync;
         /// The string ID for the setting, usable as an identifier in the database.
@@ -80,7 +79,7 @@ pub mod settings {
         }
     }
     impl private::Sealed for SiteName {}
-    impl Setting<'_> for SiteName {
+    impl Setting for SiteName {
         type Data = String;
         const ID: &'static str = "site_name";
 
@@ -96,7 +95,7 @@ pub mod settings {
     #[derive(Debug, Default, serde::Deserialize, serde::Serialize, Clone, Copy, PartialEq, Eq)]
     pub struct Webring(bool);
     impl private::Sealed for Webring {}
-    impl Setting<'_> for Webring {
+    impl Setting for Webring {
         type Data = bool;
         const ID: &'static str = "webring";
 
@@ -210,39 +209,38 @@ pub type Result<T> = std::result::Result<T, StorageError>;
 ///
 /// Implementations should note that all methods listed on this trait MUST be fully atomic
 /// or lock the database so that write conflicts or reading half-written data should not occur.
-#[async_trait]
 pub trait Storage: std::fmt::Debug + Clone + Send + Sync {
     /// Initialize Self from a URL, possibly performing initialization.
-    async fn new(url: &'_ url::Url) -> Result<Self>;
+    fn new(url: &url::Url) -> impl Future<Output = Result<Self>> + Send;
     /// Return the list of categories used in blog posts of a specified blog.
-    async fn categories(&self, url: &str) -> Result<Vec<String>>;
+    fn categories(&self, url: &str) -> impl Future<Output = Result<Vec<String>>> + Send;
 
     /// Check if a post exists in the database.
-    async fn post_exists(&self, url: &str) -> Result<bool>;
+    fn post_exists(&self, url: &str) -> impl Future<Output = Result<bool>> + Send;
 
     /// Load a post from the database in MF2-JSON format, deserialized from JSON.
-    async fn get_post(&self, url: &str) -> Result<Option<serde_json::Value>>;
+    fn get_post(&self, url: &str) -> impl Future<Output = Result<Option<serde_json::Value>>> + Send;
 
     /// Save a post to the database as an MF2-JSON structure.
     ///
     /// Note that the `post` object MUST have `post["properties"]["uid"][0]` defined.
-    async fn put_post(&self, post: &'_ serde_json::Value, user: &url::Url) -> Result<()>;
+    fn put_post(&self, post: &serde_json::Value, user: &url::Url) -> impl Future<Output = Result<()>> + Send;
 
     /// Add post to feed. Some database implementations might have optimized ways to do this.
     #[tracing::instrument(skip(self))]
-    async fn add_to_feed(&self, feed: &'_ str, post: &'_ str) -> Result<()> {
+    fn add_to_feed(&self, feed: &str, post: &str) -> impl Future<Output = Result<()>> + Send {
         tracing::debug!("Inserting {} into {} using `update_post`", post, feed);
         self.update_post(feed, serde_json::from_value(
             serde_json::json!({"add": {"children": [post]}})).unwrap()
-        ).await
+        )
     }
     /// Remove post from feed. Some database implementations might have optimized ways to do this.
     #[tracing::instrument(skip(self))]
-    async fn remove_from_feed(&self, feed: &str, post: &str) -> Result<()> {
+    fn remove_from_feed(&self, feed: &str, post: &str) -> impl Future<Output = Result<()>> + Send {
         tracing::debug!("Removing {} into {} using `update_post`", post, feed);
         self.update_post(feed, serde_json::from_value(
             serde_json::json!({"delete": {"children": [post]}})).unwrap()
-        ).await
+        )
     }
 
     /// Modify a post using an update object as defined in the
@@ -253,11 +251,11 @@ pub trait Storage: std::fmt::Debug + Clone + Send + Sync {
     /// each other's changes or simply corrupting something. Rejecting
     /// is allowed in case of concurrent updates if waiting for a lock
     /// cannot be done.
-    async fn update_post(&self, url: &str, update: MicropubUpdate) -> Result<()>;
+    fn update_post(&self, url: &str, update: MicropubUpdate) -> impl Future<Output = Result<()>> + Send;
 
     /// Get a list of channels available for the user represented by
     /// the `user` domain to write to.
-    async fn get_channels(&self, user: &url::Url) -> Result<Vec<MicropubChannel>>;
+    fn get_channels(&self, user: &url::Url) -> impl Future<Output = Result<Vec<MicropubChannel>>> + Send;
 
     /// Fetch a feed at `url` and return an h-feed object containing
     /// `limit` posts after a post by url `after`, filtering the content
@@ -275,13 +273,14 @@ pub trait Storage: std::fmt::Debug + Clone + Send + Sync {
     /// parallel from the database, preferably make this method use a
     /// connection pool to reduce overhead of creating a database
     /// connection per post for parallel fetching.
-    async fn read_feed_with_limit(
+    #[deprecated]
+    fn read_feed_with_limit(
         &self,
-        url: &'_ str,
+        url: &str,
         after: Option<&str>,
         limit: usize,
         user: Option<&url::Url>,
-    ) -> Result<Option<serde_json::Value>>;
+    ) -> impl Future<Output = Result<Option<serde_json::Value>>> + Send;
 
     /// Fetch a feed at `url` and return an h-feed object containing
     /// `limit` posts after a `cursor` (filtering the content in
@@ -301,22 +300,22 @@ pub trait Storage: std::fmt::Debug + Clone + Send + Sync {
     /// parallel from the database, preferably make this method use a
     /// connection pool to reduce overhead of creating a database
     /// connection per post for parallel fetching.
-    async fn read_feed_with_cursor(
+    fn read_feed_with_cursor(
         &self,
         url: &'_ str,
         cursor: Option<&'_ str>,
         limit: usize,
         user: Option<&url::Url>
-    ) -> Result<Option<(serde_json::Value, Option<String>)>>;
+    ) -> impl Future<Output = Result<Option<(serde_json::Value, Option<String>)>>> + Send;
 
     /// Deletes a post from the database irreversibly. Must be idempotent.
-    async fn delete_post(&self, url: &'_ str) -> Result<()>;
+    fn delete_post(&self, url: &'_ str) -> impl Future<Output = Result<()>> + Send;
 
     /// Gets a setting from the setting store and passes the result.
-    async fn get_setting<S: Setting<'a>, 'a>(&'_ self, user: &url::Url) -> Result<S>;
+    fn get_setting<S: Setting>(&self, user: &url::Url) -> impl Future<Output = Result<S>> + Send;
 
     /// Commits a setting to the setting store.
-    async fn set_setting<S: Setting<'a> + 'a, 'a>(&self, user: &'a url::Url, value: S::Data) -> Result<()>;
+    fn set_setting<S: Setting>(&self, user: &url::Url, value: S::Data) -> impl Future<Output = Result<()>> + Send;
 
     /// Add (or update) a webmention on a certian post.
     ///
@@ -332,7 +331,7 @@ pub trait Storage: std::fmt::Debug + Clone + Send + Sync {
     ///
     /// Besides, it may even allow for nice tricks like storing the
     /// webmentions separately and rehydrating them on feed reads.
-    async fn add_or_update_webmention(&self, target: &str, mention_type: MentionType, mention: serde_json::Value) -> Result<()>;
+    fn add_or_update_webmention(&self, target: &str, mention_type: MentionType, mention: serde_json::Value) -> impl Future<Output = Result<()>> + Send;
 }
 
 #[cfg(test)]