Trait activitypub_federation::traits::Collection
source · pub trait Collection: Sized {
type Owner;
type DataType: Clone + Send + Sync;
type Kind: for<'de2> Deserialize<'de2>;
type Error;
// Required methods
fn read_local<'life0, 'life1, 'async_trait>(
owner: &'life0 Self::Owner,
data: &'life1 Data<Self::DataType>,
) -> Pin<Box<dyn Future<Output = Result<Self::Kind, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn verify<'life0, 'life1, 'life2, 'async_trait>(
json: &'life0 Self::Kind,
expected_domain: &'life1 Url,
data: &'life2 Data<Self::DataType>,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn from_json<'life0, 'life1, 'async_trait>(
json: Self::Kind,
owner: &'life0 Self::Owner,
data: &'life1 Data<Self::DataType>,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}
Expand description
Trait for federating collections
Required Associated Types§
sourcetype DataType: Clone + Send + Sync
type DataType: Clone + Send + Sync
App data type passed to handlers. Must be identical to crate::config::FederationConfigBuilder::app_data type.
sourcetype Kind: for<'de2> Deserialize<'de2>
type Kind: for<'de2> Deserialize<'de2>
The type of protocol struct which gets sent over network to federate this database struct.
Required Methods§
sourcefn read_local<'life0, 'life1, 'async_trait>(
owner: &'life0 Self::Owner,
data: &'life1 Data<Self::DataType>,
) -> Pin<Box<dyn Future<Output = Result<Self::Kind, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn read_local<'life0, 'life1, 'async_trait>(
owner: &'life0 Self::Owner,
data: &'life1 Data<Self::DataType>,
) -> Pin<Box<dyn Future<Output = Result<Self::Kind, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Reads local collection from database and returns it as Activitypub JSON.
sourcefn verify<'life0, 'life1, 'life2, 'async_trait>(
json: &'life0 Self::Kind,
expected_domain: &'life1 Url,
data: &'life2 Data<Self::DataType>,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn verify<'life0, 'life1, 'life2, 'async_trait>(
json: &'life0 Self::Kind,
expected_domain: &'life1 Url,
data: &'life2 Data<Self::DataType>,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Verifies that the received object is valid.
You should check here that the domain of id matches expected_domain
. Additionally you
should perform any application specific checks.
sourcefn from_json<'life0, 'life1, 'async_trait>(
json: Self::Kind,
owner: &'life0 Self::Owner,
data: &'life1 Data<Self::DataType>,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn from_json<'life0, 'life1, 'async_trait>(
json: Self::Kind,
owner: &'life0 Self::Owner,
data: &'life1 Data<Self::DataType>,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Convert object from ActivityPub type to database type.
Called when an object is received from HTTP fetch or as part of an activity. This method
should also write the received object to database. Note that there is no distinction
between create and update, so an upsert
operation should be used.