Skip to content

Commit af04c94

Browse files
committed
Revert "Remove some uses of async_trait"
This reverts commit 51bf4b3.
1 parent 6945b8d commit af04c94

File tree

8 files changed

+26
-29
lines changed

8 files changed

+26
-29
lines changed

docs/10_fetching_objects_with_unknown_type.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub enum SearchableObjects {
2626
Note(Note)
2727
}
2828
29-
29+
#[async_trait::async_trait]
3030
impl Object for SearchableDbObjects {
3131
type DataType = DbConnection;
3232
type Kind = SearchableObjects;

examples/live_federation/objects/person.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub struct Person {
6363
public_key: PublicKey,
6464
}
6565

66+
#[async_trait::async_trait]
6667
impl Object for DbUser {
6768
type DataType = DatabaseHandle;
6869
type Kind = Person;

examples/live_federation/objects/post.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct Mention {
4444
pub kind: MentionType,
4545
}
4646

47+
#[async_trait::async_trait]
4748
impl Object for DbPost {
4849
type DataType = DatabaseHandle;
4950
type Kind = Note;

examples/local_federation/objects/person.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl DbUser {
128128
}
129129
}
130130

131+
#[async_trait::async_trait]
131132
impl Object for DbUser {
132133
type DataType = DatabaseHandle;
133134
type Kind = Person;

examples/local_federation/objects/post.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub struct Note {
4141
content: String,
4242
}
4343

44+
#[async_trait::async_trait]
4445
impl Object for DbPost {
4546
type DataType = DatabaseHandle;
4647
type Kind = Note;

src/fetch/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ async fn fetch_object_http_with_accept<T: Clone, Kind: DeserializeOwned>(
109109
let mut counter = data.request_counter.fetch_add(1, Ordering::SeqCst);
110110
// fetch_add returns old value so we need to increment manually here
111111
counter += 1;
112-
url.to_string();
113112
if counter > config.http_fetch_limit {
114113
return Err(Error::RequestLimit);
115114
}

src/fetch/object_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ where
144144
data: &Data<<Kind as Object>::DataType>,
145145
) -> Result<Option<Kind>, <Kind as Object>::Error> {
146146
let id = self.0.clone();
147-
<Kind as Object>::read_from_id(*id, data).await
147+
Object::read_from_id(*id, data).await
148148
}
149149

150150
/// Fetch object from origin instance over HTTP, then verify and parse it.

src/traits/mod.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub mod either;
4646
/// content: String,
4747
/// }
4848
///
49-
///
49+
/// #[async_trait::async_trait]
5050
/// impl Object for DbPost {
5151
/// type DataType = DbConnection;
5252
/// type Kind = Note;
@@ -96,6 +96,7 @@ pub mod either;
9696
/// }
9797
///
9898
/// }
99+
#[async_trait]
99100
pub trait Object: Sized + Debug {
100101
/// App data type passed to handlers. Must be identical to
101102
/// [crate::config::FederationConfigBuilder::app_data] type.
@@ -121,29 +122,23 @@ pub trait Object: Sized + Debug {
121122
/// Try to read the object with given `id` from local database.
122123
///
123124
/// Should return `Ok(None)` if not found.
124-
fn read_from_id(
125+
async fn read_from_id(
125126
object_id: Url,
126127
data: &Data<Self::DataType>,
127-
) -> impl std::future::Future<Output = Result<Option<Self>, Self::Error>> + Send;
128+
) -> Result<Option<Self>, Self::Error>;
128129

129130
/// Mark remote object as deleted in local database.
130131
///
131132
/// Called when a `Delete` activity is received, or if fetch returns a `Tombstone` object.
132-
fn delete(
133-
self,
134-
_data: &Data<Self::DataType>,
135-
) -> impl std::future::Future<Output = Result<(), Self::Error>> + Send {
136-
async { Ok(()) }
133+
async fn delete(self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
134+
Ok(())
137135
}
138136

139137
/// Convert database type to Activitypub type.
140138
///
141139
/// Called when a local object gets fetched by another instance over HTTP, or when an object
142140
/// gets sent in an activity.
143-
fn into_json(
144-
self,
145-
data: &Data<Self::DataType>,
146-
) -> impl std::future::Future<Output = Result<Self::Kind, Self::Error>> + Send;
141+
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error>;
147142

148143
/// Verifies that the received object is valid.
149144
///
@@ -152,21 +147,18 @@ pub trait Object: Sized + Debug {
152147
///
153148
/// It is necessary to use a separate method for this, because it might be used for activities
154149
/// like `Delete/Note`, which shouldn't perform any database write for the inner `Note`.
155-
fn verify(
150+
async fn verify(
156151
json: &Self::Kind,
157152
expected_domain: &Url,
158153
data: &Data<Self::DataType>,
159-
) -> impl std::future::Future<Output = Result<(), Self::Error>> + Send;
154+
) -> Result<(), Self::Error>;
160155

161156
/// Convert object from ActivityPub type to database type.
162157
///
163158
/// Called when an object is received from HTTP fetch or as part of an activity. This method
164159
/// should write the received object to database. Note that there is no distinction between
165160
/// create and update, so an `upsert` operation should be used.
166-
fn from_json(
167-
json: Self::Kind,
168-
data: &Data<Self::DataType>,
169-
) -> impl std::future::Future<Output = Result<Self, Self::Error>> + Send;
161+
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error>;
170162
}
171163

172164
/// Handler for receiving incoming activities.
@@ -303,6 +295,7 @@ where
303295
}
304296

305297
/// Trait for federating collections
298+
#[async_trait]
306299
pub trait Collection: Sized {
307300
/// Actor or object that this collection belongs to
308301
type Owner;
@@ -315,31 +308,31 @@ pub trait Collection: Sized {
315308
type Error;
316309

317310
/// Reads local collection from database and returns it as Activitypub JSON.
318-
fn read_local(
311+
async fn read_local(
319312
owner: &Self::Owner,
320313
data: &Data<Self::DataType>,
321-
) -> impl std::future::Future<Output = Result<Self::Kind, Self::Error>> + Send;
314+
) -> Result<Self::Kind, Self::Error>;
322315

323316
/// Verifies that the received object is valid.
324317
///
325318
/// You should check here that the domain of id matches `expected_domain`. Additionally you
326319
/// should perform any application specific checks.
327-
fn verify(
320+
async fn verify(
328321
json: &Self::Kind,
329322
expected_domain: &Url,
330323
data: &Data<Self::DataType>,
331-
) -> impl std::future::Future<Output = Result<(), Self::Error>> + Send;
324+
) -> Result<(), Self::Error>;
332325

333326
/// Convert object from ActivityPub type to database type.
334327
///
335328
/// Called when an object is received from HTTP fetch or as part of an activity. This method
336329
/// should also write the received object to database. Note that there is no distinction
337330
/// between create and update, so an `upsert` operation should be used.
338-
fn from_json(
331+
async fn from_json(
339332
json: Self::Kind,
340333
owner: &Self::Owner,
341334
data: &Data<Self::DataType>,
342-
) -> impl std::future::Future<Output = Result<Self, Self::Error>> + Send;
335+
) -> Result<Self, Self::Error>;
343336
}
344337

345338
/// Some impls of these traits for use in tests. Dont use this from external crates.
@@ -348,15 +341,14 @@ pub trait Collection: Sized {
348341
#[doc(hidden)]
349342
#[allow(clippy::unwrap_used)]
350343
pub mod tests {
351-
use super::{ActivityHandler, Actor, Data, Debug, Object, PublicKey, Url};
344+
use super::{async_trait, ActivityHandler, Actor, Data, Debug, Object, PublicKey, Url};
352345
use crate::{
353346
error::Error,
354347
fetch::object_id::ObjectId,
355348
http_signatures::{generate_actor_keypair, Keypair},
356349
protocol::verification::verify_domains_match,
357350
};
358351
use activitystreams_kinds::{activity::FollowType, actor::PersonType};
359-
use async_trait::async_trait;
360352
use serde::{Deserialize, Serialize};
361353
use std::sync::LazyLock;
362354

@@ -413,6 +405,7 @@ pub mod tests {
413405
local: false,
414406
});
415407

408+
#[async_trait]
416409
impl Object for DbUser {
417410
type DataType = DbConnection;
418411
type Kind = Person;
@@ -516,6 +509,7 @@ pub mod tests {
516509
#[derive(Debug, Clone)]
517510
pub struct DbPost {}
518511

512+
#[async_trait]
519513
impl Object for DbPost {
520514
type DataType = DbConnection;
521515
type Kind = Note;

0 commit comments

Comments
 (0)