@@ -46,7 +46,7 @@ pub mod either;
46
46
/// content: String,
47
47
/// }
48
48
///
49
- ///
49
+ /// #[async_trait::async_trait]
50
50
/// impl Object for DbPost {
51
51
/// type DataType = DbConnection;
52
52
/// type Kind = Note;
@@ -96,6 +96,7 @@ pub mod either;
96
96
/// }
97
97
///
98
98
/// }
99
+ #[ async_trait]
99
100
pub trait Object : Sized + Debug {
100
101
/// App data type passed to handlers. Must be identical to
101
102
/// [crate::config::FederationConfigBuilder::app_data] type.
@@ -121,29 +122,23 @@ pub trait Object: Sized + Debug {
121
122
/// Try to read the object with given `id` from local database.
122
123
///
123
124
/// Should return `Ok(None)` if not found.
124
- fn read_from_id (
125
+ async fn read_from_id (
125
126
object_id : Url ,
126
127
data : & Data < Self :: DataType > ,
127
- ) -> impl std :: future :: Future < Output = Result < Option < Self > , Self :: Error > > + Send ;
128
+ ) -> Result < Option < Self > , Self :: Error > ;
128
129
129
130
/// Mark remote object as deleted in local database.
130
131
///
131
132
/// 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 ( ( ) )
137
135
}
138
136
139
137
/// Convert database type to Activitypub type.
140
138
///
141
139
/// Called when a local object gets fetched by another instance over HTTP, or when an object
142
140
/// 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 > ;
147
142
148
143
/// Verifies that the received object is valid.
149
144
///
@@ -152,21 +147,18 @@ pub trait Object: Sized + Debug {
152
147
///
153
148
/// It is necessary to use a separate method for this, because it might be used for activities
154
149
/// like `Delete/Note`, which shouldn't perform any database write for the inner `Note`.
155
- fn verify (
150
+ async fn verify (
156
151
json : & Self :: Kind ,
157
152
expected_domain : & Url ,
158
153
data : & Data < Self :: DataType > ,
159
- ) -> impl std :: future :: Future < Output = Result < ( ) , Self :: Error > > + Send ;
154
+ ) -> Result < ( ) , Self :: Error > ;
160
155
161
156
/// Convert object from ActivityPub type to database type.
162
157
///
163
158
/// Called when an object is received from HTTP fetch or as part of an activity. This method
164
159
/// should write the received object to database. Note that there is no distinction between
165
160
/// 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 > ;
170
162
}
171
163
172
164
/// Handler for receiving incoming activities.
@@ -303,6 +295,7 @@ where
303
295
}
304
296
305
297
/// Trait for federating collections
298
+ #[ async_trait]
306
299
pub trait Collection : Sized {
307
300
/// Actor or object that this collection belongs to
308
301
type Owner ;
@@ -315,31 +308,31 @@ pub trait Collection: Sized {
315
308
type Error ;
316
309
317
310
/// Reads local collection from database and returns it as Activitypub JSON.
318
- fn read_local (
311
+ async fn read_local (
319
312
owner : & Self :: Owner ,
320
313
data : & Data < Self :: DataType > ,
321
- ) -> impl std :: future :: Future < Output = Result < Self :: Kind , Self :: Error > > + Send ;
314
+ ) -> Result < Self :: Kind , Self :: Error > ;
322
315
323
316
/// Verifies that the received object is valid.
324
317
///
325
318
/// You should check here that the domain of id matches `expected_domain`. Additionally you
326
319
/// should perform any application specific checks.
327
- fn verify (
320
+ async fn verify (
328
321
json : & Self :: Kind ,
329
322
expected_domain : & Url ,
330
323
data : & Data < Self :: DataType > ,
331
- ) -> impl std :: future :: Future < Output = Result < ( ) , Self :: Error > > + Send ;
324
+ ) -> Result < ( ) , Self :: Error > ;
332
325
333
326
/// Convert object from ActivityPub type to database type.
334
327
///
335
328
/// Called when an object is received from HTTP fetch or as part of an activity. This method
336
329
/// should also write the received object to database. Note that there is no distinction
337
330
/// between create and update, so an `upsert` operation should be used.
338
- fn from_json (
331
+ async fn from_json (
339
332
json : Self :: Kind ,
340
333
owner : & Self :: Owner ,
341
334
data : & Data < Self :: DataType > ,
342
- ) -> impl std :: future :: Future < Output = Result < Self , Self :: Error > > + Send ;
335
+ ) -> Result < Self , Self :: Error > ;
343
336
}
344
337
345
338
/// Some impls of these traits for use in tests. Dont use this from external crates.
@@ -348,15 +341,14 @@ pub trait Collection: Sized {
348
341
#[ doc( hidden) ]
349
342
#[ allow( clippy:: unwrap_used) ]
350
343
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 } ;
352
345
use crate :: {
353
346
error:: Error ,
354
347
fetch:: object_id:: ObjectId ,
355
348
http_signatures:: { generate_actor_keypair, Keypair } ,
356
349
protocol:: verification:: verify_domains_match,
357
350
} ;
358
351
use activitystreams_kinds:: { activity:: FollowType , actor:: PersonType } ;
359
- use async_trait:: async_trait;
360
352
use serde:: { Deserialize , Serialize } ;
361
353
use std:: sync:: LazyLock ;
362
354
@@ -413,6 +405,7 @@ pub mod tests {
413
405
local : false ,
414
406
} ) ;
415
407
408
+ #[ async_trait]
416
409
impl Object for DbUser {
417
410
type DataType = DbConnection ;
418
411
type Kind = Person ;
@@ -516,6 +509,7 @@ pub mod tests {
516
509
#[ derive( Debug , Clone ) ]
517
510
pub struct DbPost { }
518
511
512
+ #[ async_trait]
519
513
impl Object for DbPost {
520
514
type DataType = DbConnection ;
521
515
type Kind = Note ;
0 commit comments