Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove use of async-trait for Rust 1.75.0+ #92

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
dwn-rs
====
# dwn-rs

dwn-rs is a Rust-based DWN implementation that can be
used with [dwn-sdk-js](https://github.com/TBD54566975/dwn-sdk-js).

# Compiling

## Requirements

- Rust 1.75.0+

This project uses [cargo-make](https://sagiegurari.github.io/cargo-make/). To
install it, run:

Expand Down
1 change: 0 additions & 1 deletion crates/dwn-rs-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ description = "Core library components for dwn-rs"
crate-type = ["cdylib", "rlib"]

[dependencies]
async-trait = "0.1.73"
chrono = { version = "0.4.30", features = ["serde"] }
cid = { version = "0.11.1", features = ["serde"] }
futures-util = "0.3.30"
Expand Down
8 changes: 5 additions & 3 deletions crates/dwn-rs-core/src/filters/query.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::future::Future;

use crate::value::Value;
use async_trait::async_trait;
use ipld_core::cid::Cid;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
Expand Down Expand Up @@ -159,7 +160,6 @@ pub struct QueryReturn<T> {
}

// Trait for implementing Filters
#[async_trait]
pub trait Query<U, T>
where
U: DeserializeOwned,
Expand All @@ -172,5 +172,7 @@ where
fn page(&mut self, pagination: Option<Pagination>) -> &mut Self;
fn always_cursor(&mut self) -> &mut Self;
fn sort(&mut self, sort: Option<T>) -> &mut Self;
async fn query(&self) -> Result<(Vec<U>, Option<crate::Cursor>), errors::QueryError>;
fn query(
&self,
) -> impl Future<Output = Result<(Vec<U>, Option<crate::Cursor>), errors::QueryError>> + Send;
}
105 changes: 60 additions & 45 deletions crates/dwn-rs-core/src/stores.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{fmt::Debug, pin::Pin};
use std::{fmt::Debug, future::Future, pin::Pin};

use async_trait::async_trait;
use futures_util::Stream;
use ipld_core::cid::Cid;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
Expand All @@ -13,63 +12,70 @@ use crate::{
};
use crate::{MapValue, Message};

#[async_trait]
pub trait MessageStore: Default {
async fn open(&mut self) -> Result<(), MessageStoreError>;
fn open(&mut self) -> impl Future<Output = Result<(), MessageStoreError>> + Send;

async fn close(&mut self);
fn close(&mut self) -> impl Future<Output = ()>;

async fn put(
fn put(
&self,
tenant: &str,
message: Message,
indexes: MapValue,
tags: MapValue,
) -> Result<Cid, MessageStoreError>;
) -> impl Future<Output = Result<Cid, MessageStoreError>> + Send;

async fn get(&self, tenant: &str, cid: String) -> Result<Message, MessageStoreError>;
fn get(
&self,
tenant: &str,
cid: String,
) -> impl Future<Output = Result<Message, MessageStoreError>> + Send;

async fn query(
fn query(
&self,
tenant: &str,
filter: Filters,
sort: Option<MessageSort>,
pagination: Option<Pagination>,
) -> Result<QueryReturn<Message>, MessageStoreError>;
) -> impl Future<Output = Result<QueryReturn<Message>, MessageStoreError>> + Send;

async fn delete(&self, tenant: &str, cid: String) -> Result<(), MessageStoreError>;
fn delete(
&self,
tenant: &str,
cid: String,
) -> impl Future<Output = Result<(), MessageStoreError>> + Send;

async fn clear(&self) -> Result<(), MessageStoreError>;
fn clear(&self) -> impl Future<Output = Result<(), MessageStoreError>> + Send;
}

#[async_trait]
pub trait DataStore: Default {
async fn open(&mut self) -> Result<(), DataStoreError>;
fn open(&mut self) -> impl Future<Output = Result<(), DataStoreError>> + Send;

async fn close(&mut self);
fn close(&mut self) -> impl Future<Output = ()> + Send;

async fn put<T: Stream<Item = Vec<u8>> + Send + Unpin>(
fn put<T: Stream<Item = Vec<u8>> + Send + Unpin>(
&self,
tenant: &str,
record_id: String,
cid: String,
value: T,
) -> Result<PutDataResults, DataStoreError>;
) -> impl Future<Output = Result<PutDataResults, DataStoreError>> + Send;

async fn get(
fn get(
&self,
tenant: &str,
record_id: String,
cid: String,
) -> Result<GetDataResults, DataStoreError>;
async fn delete(
) -> impl Future<Output = Result<GetDataResults, DataStoreError>> + Send;

fn delete(
&self,
tenant: &str,
record_id: String,
cid: String,
) -> Result<(), DataStoreError>;
) -> impl Future<Output = Result<(), DataStoreError>> + Send;

async fn clear(&self) -> Result<(), DataStoreError>;
fn clear(&self) -> impl Future<Output = Result<(), DataStoreError>> + Send;
}

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -83,36 +89,39 @@ pub struct GetDataResults {
pub data: Pin<Box<dyn Stream<Item = Vec<u8>>>>,
}

#[async_trait]
pub trait EventLog: Default {
async fn open(&mut self) -> Result<(), EventLogError>;
fn open(&mut self) -> impl Future<Output = Result<(), EventLogError>> + Send;

async fn close(&mut self);
fn close(&mut self) -> impl Future<Output = ()>;

async fn append(
fn append(
&self,
tenant: &str,
cid: String,
indexes: MapValue,
tags: MapValue,
) -> Result<(), EventLogError>;
) -> impl Future<Output = Result<(), EventLogError>>;

async fn get_events(
fn get_events(
&self,
tenant: &str,
cursor: Option<Cursor>,
) -> Result<QueryReturn<String>, EventLogError>;
) -> impl Future<Output = Result<QueryReturn<String>, EventLogError>> + Send;

async fn query_events(
fn query_events(
&self,
tenant: &str,
filter: Filters,
cursor: Option<Cursor>,
) -> Result<QueryReturn<String>, EventLogError>;
) -> impl Future<Output = Result<QueryReturn<String>, EventLogError>> + Send;

async fn delete<'a>(&self, tenant: &str, cid: &'a [&str]) -> Result<(), EventLogError>;
fn delete<'a>(
&self,
tenant: &str,
cid: &'a [&str],
) -> impl Future<Output = Result<(), EventLogError>> + Send;

async fn clear(&self) -> Result<(), EventLogError>;
fn clear(&self) -> impl Future<Output = Result<(), EventLogError>> + Send;
}

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -123,31 +132,37 @@ pub struct ManagedResumableTask<T: Serialize + Sync + Send + Debug> {
pub retry_count: u64,
}

#[async_trait]
pub trait ResumableTaskStore: Default {
async fn open(&mut self) -> Result<(), ResumableTaskStoreError>;
fn open(&mut self) -> impl Future<Output = Result<(), ResumableTaskStoreError>> + Send;

async fn close(&mut self);
fn close(&mut self) -> impl Future<Output = ()> + Send;

async fn register<T: Serialize + Send + Sync + DeserializeOwned + Debug>(
fn register<T: Serialize + Send + Sync + DeserializeOwned + Debug>(
&self,
task: T,
timeout: u64,
) -> Result<ManagedResumableTask<T>, ResumableTaskStoreError>;
) -> impl Future<Output = Result<ManagedResumableTask<T>, ResumableTaskStoreError>> + Send;

async fn grab<T: Serialize + Send + Sync + DeserializeOwned + Debug + Unpin>(
fn grab<T: Serialize + Send + Sync + DeserializeOwned + Debug + Unpin>(
&self,
count: u64,
) -> Result<Vec<ManagedResumableTask<T>>, ResumableTaskStoreError>;
) -> impl Future<Output = Result<Vec<ManagedResumableTask<T>>, ResumableTaskStoreError>> + Send;

async fn read<T: Serialize + Send + Sync + DeserializeOwned + Debug>(
fn read<T: Serialize + Send + Sync + DeserializeOwned + Debug>(
&self,
task_id: String,
) -> Result<Option<ManagedResumableTask<T>>, ResumableTaskStoreError>;
) -> impl Future<Output = Result<Option<ManagedResumableTask<T>>, ResumableTaskStoreError>> + Send;

async fn extend(&self, task_id: String, timeout: u64) -> Result<(), ResumableTaskStoreError>;
fn extend(
&self,
task_id: String,
timeout: u64,
) -> impl Future<Output = Result<(), ResumableTaskStoreError>> + Send;

async fn delete(&self, task_id: String) -> Result<(), ResumableTaskStoreError>;
fn delete(
&self,
task_id: String,
) -> impl Future<Output = Result<(), ResumableTaskStoreError>> + Send;

async fn clear(&self) -> Result<(), ResumableTaskStoreError>;
fn clear(&self) -> impl Future<Output = Result<(), ResumableTaskStoreError>> + Send;
}
1 change: 0 additions & 1 deletion crates/dwn-rs-stores/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ surreal-wasm = ["surrealdb", "surrealdb/kv-indxdb"]

[dependencies]
async-stream = "0.3.5"
async-trait = "0.1.73"
futures-util = "0.3.30"
chrono = { version = "0.4.37", features = ["serde", "wasmbind"] }
cid = { version = "0.11.1", features = ["serde"] }
Expand Down
2 changes: 0 additions & 2 deletions crates/dwn-rs-stores/src/surrealdb/data_store.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use async_stream::stream;
use async_trait::async_trait;
use futures_util::{pin_mut, Stream, StreamExt};
use surrealdb::sql::{Id, Table, Thing};

Expand All @@ -13,7 +12,6 @@ use super::models::{CreateData, GetData};

const DATA_TABLE: &str = "data";

#[async_trait]
impl DataStore for SurrealDB {
async fn open(&mut self) -> Result<(), DataStoreError> {
self.open().await.map_err(DataStoreError::from)
Expand Down
2 changes: 0 additions & 2 deletions crates/dwn-rs-stores/src/surrealdb/event_log.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use async_trait::async_trait;
use surrealdb::sql::{Id, Table, Thing};

use crate::{SurrealDB, SurrealDBError, SurrealQuery};
Expand All @@ -13,7 +12,6 @@ use super::models::{CreateEvent, GetEvent};

const EVENTS_TABLE: &str = "events";

#[async_trait]
impl EventLog for SurrealDB {
async fn open(&mut self) -> Result<(), EventLogError> {
self.open().await.map_err(EventLogError::from)
Expand Down
2 changes: 0 additions & 2 deletions crates/dwn-rs-stores/src/surrealdb/message_store.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::str::FromStr;

use async_trait::async_trait;
use cid::Cid;
use multihash_codetable::{Code, MultihashDigest};
use surrealdb::sql::{Id, Thing};
Expand All @@ -23,7 +22,6 @@ use super::{

const MESSAGES_TABLE: &str = "messages";

#[async_trait]
impl MessageStore for SurrealDB {
async fn open(&mut self) -> Result<(), MessageStoreError> {
self.open().await.map_err(MessageStoreError::from)
Expand Down
2 changes: 0 additions & 2 deletions crates/dwn-rs-stores/src/surrealdb/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
ops::{Bound, RangeBounds},
};

use async_trait::async_trait;
use serde::de::DeserializeOwned;
use surrealdb::sql::{value as surreal_value, Cond, Function, Idiom, Subquery};
use surrealdb::{
Expand Down Expand Up @@ -69,7 +68,6 @@ pub trait CursorValue<T> {
fn cursor_value(&self, sort: T) -> dwn_rs_core::value::Value;
}

#[async_trait]
impl<U, T> Query<U, T> for SurrealQuery<U, T>
where
U: CursorValue<T> + DeserializeOwned + Sync + Send + Debug,
Expand Down
2 changes: 0 additions & 2 deletions crates/dwn-rs-stores/src/surrealdb/resumable_task_store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use async_trait::async_trait;
use serde::{de::DeserializeOwned, Serialize};
use std::fmt::Debug;
use surrealdb::sql::{
Expand All @@ -22,7 +21,6 @@ const RESUMABLE_TASKS_DB: &str = "tasks";
const RESUMABLE_TASKS_TABLE: &str = "resumable_tasks";
const TASK_TIMEOUT: u64 = 60;

#[async_trait]
impl ResumableTaskStore for SurrealDB {
async fn open(&mut self) -> Result<(), ResumableTaskStoreError> {
self.db = self.db.clone();
Expand Down
Loading